码迷,mamicode.com
首页 > Web开发 > 详细

css3动画

时间:2019-01-12 12:03:33      阅读:999      评论:0      收藏:0      [点我收藏+]

标签:mat   yellow   改变   set   百分比   相同   head   height   color   

@keyframes规则是创建动画。 @keyframes规则内指定一个CSS样式和动画将逐步从目前的样式更改为新的样式。

动画是使元素从一种样式逐渐变化为另一种样式的效果。

您可以改变任意多的样式任意多的次数。

请用百分比来规定变化发生的时间,或用关键词 "from" 和 "to",等同于 0% 和 100%。

0% 是动画的开始,100% 是动画的完成。

为了得到最佳的浏览器支持,您应该始终定义 0% 和 100% 选择器。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>css3动画</title>
<style> 
div
{
    width:100px;
    height:100px;
    background:red;
    position:relative;
    animation-name:myfirst;     //规定 @keyframes 动画的名称。
    animation-duration:5s;    //规定动画完成一个周期所花费的秒或毫秒。默认是 0。
    animation-timing-function:linear;       //规定动画的速度曲线。默认是"ease"。
    animation-delay:2s;             //规定动画何时开始。默认是 0。
    animation-iteration-count:infinite;   //规定动画被播放的次数。默认是 1。
    animation-direction:alternate;       //规定动画是否在下一周期逆向地播放。默认是 "normal"。
    animation-play-state:running;      //规定动画是否正在运行或暂停。默认是 "running"。
}

@keyframes myfirst   
{
    0%   {background:red; left:0px; top:0px;}
    25%  {background:yellow; left:200px; top:0px;}
    50%  {background:blue; left:200px; top:200px;}
    75%  {background:green; left:0px; top:200px;}
    100% {background:red; left:0px; top:0px;}
}


</style>
</head>
<body>

<div></div>

</body>
</html>

 

与上面动画相同,但是使用了简写的动画 animation 属性:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>动画简写</title>
<style> 
div
{
    width:100px;
    height:100px;
    background:red;
    position:relative;
    animation:myfirst 5s linear 2s infinite alternate;
}

@keyframes myfirst
{
    0%   {background:red; left:0px; top:0px;}
    25%  {background:yellow; left:200px; top:0px;}
    50%  {background:blue; left:200px; top:200px;}
    75%  {background:green; left:0px; top:200px;}
    100% {background:red; left:0px; top:0px;}
}
</style>
</head>
<body>

<div></div>

</body>
</html>

 

css3动画

标签:mat   yellow   改变   set   百分比   相同   head   height   color   

原文地址:https://www.cnblogs.com/tanchangsha/p/10258966.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!