CSS3 animation,@keyframes 动画

今天看到一个很酷的logo看了下他用的是animation 动画效果,就拿来做例子

浏览器支持

Internet Explorer 10、Firefox 以及 Opera 支持 animation 属性。

Safari 和 Chrome 支持替代的 -webkit-animation 属性。

注释:Internet Explorer 9 以及更早的版本不支持 animation 属性。

定义和用法

animation 属性是一个简写属性,用于设置六个动画属性:

  • animation-name
  • animation-duration
  • animation-timing-function
  • animation-delay
  • animation-iteration-count
  • animation-direction

注释:请始终规定 animation-duration 属性,否则时长为 0,就不会播放动画了。

默认值:none 0 ease 0 1 normal
继承性:no
版本:CSS3
JavaScript 语法:object.style.animation="mymove 5s infinite"

语法

animation: name duration timing-function delay iteration-count direction;
描述
animation-name规定需要绑定到选择器的 keyframe 名称。。
animation-duration规定完成动画所花费的时间,以秒或毫秒计。
animation-timing-function规定动画的速度曲线。
animation-delay规定在动画开始之前的延迟。
animation-iteration-count规定动画应该播放的次数。
animation-direction规定是否应该轮流反向播放动画。

 

下面是w3school的实例,

复制代码
<!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>
复制代码

这是站点logo使用的动画效果

<div id="logo"></div>

#logo {
    animation: 1s steps(16) 0s reverse none infinite running logo;
    background: transparent url("seclogo.png") no-repeat scroll 0 0;
  width: 195px;
    height: 150px;
}
当然要做下兼容
@-webkit-keyframes logo {
    from { background-position: 0px; }
    to { background-position: -3120px; }
}
@-moz-keyframes logo {
    from { background-position: 0px; }
    to { background-position: -3120px; }
}
@-o-keyframes logo {
    from { background-position: 0px; }
    to { background-position: -3120px; }
}

好简单就出了一个跳动的动作,很强大啊, 调整steps(16)中的数字还能实现左右滑动效果 ,1s自然就是跳动的频率了,不过加快动作好像不行,慢动作却是可以。
附上 seclogo.png图 大家可以测试看看,效果还是可以得,借鉴中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值