CSS3 动画animation

CSS3 动画属性animation

语法:animation: name duration timing-function delay iteration-count direction;

下面的表格列出了 @keyframes 规则和所有动画属性:

属性描述CSS
@keyframes规定动画。3
animation所有动画属性的简写属性,除了 animation-play-state 属性。3
animation-name规定 @keyframes 动画的名称。3
animation-duration规定动画完成一个周期所花费的秒或毫秒。默认是 0。3
animation-timing-function规定动画的速度曲线。默认是 "ease"。3
animation-delay规定动画何时开始。默认是 0。3
animation-iteration-count规定动画被播放的次数。默认是 1。3
animation-direction规定动画是否在下一周期逆向地播放。默认是 "normal"。3
animation-play-state规定动画是否正在运行或暂停。默认是 "running"。3
animation-fill-mode规定对象动画时间之外的状态。3

 

在 @keyframes 中创建动画时,请把它捆绑到某个选择器,否则不会产生动画效果。

通过规定至少以下两项 CSS3 动画属性,即可将动画绑定到选择器:(infinite:无限循环)

  • 规定动画的名称
  • 规定动画的时长

 

eg:

div
{
animation: myfirst 5s;
-moz-animation: myfirst 5s;	/* Firefox */
-webkit-animation: myfirst 5s;	/* Safari 和 Chrome */
-o-animation: myfirst 5s;	/* Opera */
}

 

什么是 CSS3 中的动画?

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

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

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

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

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

 

eg:

1.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>animation</title>
    <link rel="stylesheet" href="style/animation.css"/>
    <link rel="stylesheet" href="style/animation-color.css"/>
</head>
<body>
<div class="animation"></div>
<div class="animation-color"></div>
</body>
</html>

 

2.css3 移动

.animation{
    width: 100px;
    height: 100px;
    background-color: #2b81e2;
    position:relative;
    animation: move 6s infinite;
    -webkit-animation: move 6s infinite;
}

@keyframes move {
    from {
        left: 0;
        top: 0;
    }
    to{
        left: 300px;
        top: 300px;
    }
}

@-webkit-keyframes move {
    from {
        left: 0;
        top: 0;
    }
    to{
        left: 300px;
        top: 300px;
    }
}

 

3.css3 变色

.animation-color{
    width: 100px;
    height: 100px;
    background-color: #66e229;
    animation: moveColor 5s infinite;
    -webkit-animation: moveColor 5s infinite;
}

@keyframes moveColor {
    from{
        background-color: #66e229;
    }
    to{
        background-color: #9fa8ef;
    }
}

@-webkit-keyframes moveColor {
    from{
        background-color: #66e229;
    }
    to{
        background-color: #9fa8ef;
    }
}

 

4.效果

 图一:

 

 图二:

 

 图三:

 

转载于:https://www.cnblogs.com/Michelle20180227/p/8680991.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值