.bolang { animation: bg 1s linear infinite; background-image: url(./static/bolan3.png); background-repeat: repeat; background-size: 100vw 12.8vw; border-radius: 3.2vw; overflow: hidden; padding: 0 5.333vw; z-index: -10; } @-webkit-keyframes bg { to { background-position: 0 -25.6vw; } } @keyframes bg { to { background-position: 0 -25.6vw; } }
CSS3 @keyframes 规则
使用@keyframes规则,你可以创建动画。
创建动画是通过逐步改变从一个CSS样式设定到另一个。
在动画过程中,您可以更改CSS样式的设定多次。
指定的变化时发生时使用%,或关键字"from"和"to",这是和0%到100%相同。
0%是开头动画,100%是当动画完成。
为了获得最佳的浏览器支持,您应该始终定义为0%和100%的选择器。
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <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 {top:0px;} to {top:200px;} } @-webkit-keyframes mymove /* Safari and Chrome */ { from {top:0px;} to {top:200px;} } </style> </head> <body> <p><strong>注意:</strong> @keyframes 规则 不兼容 IE 9 以及更早版本的浏览器.</p> <div></div> </body> </html>