实现思路
通过改变字母的top值
每个字母不能同时运动,通过延迟时间,for循环 2s (i*50)ms ...
infinite 动画会无限次地循环播放。
alternate 播放次数是奇数时,动画向原方向播放;播放次数是偶数时,动画向反方向播放
静态效果图
实例代码
代码如下 | 复制代码 |
@keyframes move{ 0%{ top: 0; } 100%{ top: 10px; } } @-webkit-keyframes move{ 0%{ top: 0; } 100%{ top: 10px; } } #box { width: 200px; height: 100px; background: red; font-size: 20px; color: #fff; } #box span { position: relative; /*animation: .2s move linear infinite alternate; */ }
window.onload = function() { var span = document.querySelectorAll('#box span'); for(var i = 0; i span[i].style.WebkitAnimation=span[i].style.animation=" .2s "+(i*50)+"ms move linear infinite alternate"; } }; L o a d i n g |