实例:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> div{ width: 100px; height: 100px; background: red; /*动画名字(动画的名字要有语义化)*/ /*animation-name:movedh ;*/ /*动画完成的时间*/ /*animation-duration: 1s;*/ /*动画播放次数*/ /*animation-iteration-count: 3;*/ /*animation-iteration-count: infinite;*/ /*综合写法*/ animation: movedh 1s 2s infinite; } div:hover{ /*播放/暂停*/ animation-play-state:paused; } /*关键帧*/ @keyframes movedh{ from{ width: 100px; } to{ width: 1000px; } } </style> </head> <body> <div></div> </body> </html>实例:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> .wrap{ width: 500px; height: 500px; border: 1px solid red; margin: 100px auto; position: relative; } .box{ width: 100px; height: 100px; background: yellow; position: absolute; animation: movedh 2s infinite alternate; } @keyframes movedh{ 0%{ left:0; top:0; } 25%{ left:400px; top:0; border-radius:50% ; background: -webkit-linear-gradient(red,blue); } 50%{ left:400px; top:400px; } 75%{ left:0px; top:400px; border-radius:50% ; } 100%{ left:0px; top:0; } } </style> </head> <body> <div class="wrap"> <div class="box"></div> </div> </body> </html>