標籤:inf strong doctype scale doc form exp 元素 支援
利用CSS中animation為元素添加動畫,代碼格式為:
animation:動畫名 .75s infinite;
-webkit-animation:動畫名 .75s infinite; /*Safari and Chrome*/
第二句是為了相容Google瀏覽器等,在指定動畫時需要將元素指定為相對定位:position:relative;
接著為動畫指定效果:
@keyframes 動畫名
{
from {transform: none;}
to {transform: scale(1.6);}
}
@-webkit-keyframes 動畫名
{
from {-webkit-transform: none;}
to {-webkit-transform: scale(1.6);}
}
完整例子:
效果連結:http://www.w3school.com.cn/tiy/t.asp?f=css3_animation
<!DOCTYPE html>
<html>
<head>
<style>
div
{
width:100px;
height:100px;
background:red;
position:relative;
animation:mymove 5s infinite;
-webkit-animation:mymove 5s infinite; /*Safari and Chrome*/
}
@keyframes mymove
{
from {left:0px;}
to {left:200px;}
}
@-webkit-keyframes mymove /*Safari and Chrome*/
{
from {left:0px;}
to {left:200px;}
}
</style>
</head>
<body>
<p><strong>注釋:</strong>Internet Explorer 9 以及更早的版本不支援 animation 屬性。</p>
<div></div>
</body>
</html>
CSS3動畫效果animation