DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> CSS入門知識 >> CSS3基礎
11.8 播放方向 animation-direction 屬性
編輯:CSS3基礎     

一、animation-direction 屬性

這個屬性決定每一輪迴圈要順著播還是倒著播。

語法:

animation-direction:取值;

animation-direction 屬性取值
屬性值說明
normal每次循環都正向播放(預設值)
reverse每次循環都反向播放
alternate奇數次正向播放,偶數次反向播放

舉例:

<!DOCTYPE html>
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<title>CSS3 animation-direction屬性</title>
<style type="text/css">
@-webkit-keyframes mytranslate {
  0%{}
  100%{-webkit-transform:translateX(100px);}
}
#div1 {
  width:40px;
  height:40px;
  border-radius:20px;
  background-color:red;
  -webkit-animation-name:mytranslate;
  -webkit-animation-timing-function:linear;
  -webkit-animation-duration:2s;
}
#container {
  display:inline-block;
  width:140px;
  border:1px solid silver;
}
</style>
</head>
<body>
<div id="container">
<div id="div1"></div>
</div>
</body>
</html>

分析:

預設的 normal 是沿正方向播放(0% 到 100%),小球由左往右滾動。

-webkit-animation-direction:reverse;

加上這行之後,動畫改為反向播放(100% 到 0%),小球就變成由右往左滾。

若把取值改成 alternate,效果會更有意思:第一輪由左往右,第二輪由右往左,於是形成自然的來回擺動。實務上做載入動畫、呼吸效果時,alternate 搭配 infinite 是最常用的組合。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved