我正在尝试为 div 的背景位置设置动画,速度很慢,但不会出现抖动。你可以在这里看到我当前努力的结果:
@-webkit-keyframes MOVE-BG {
from {
background-position: 0% 0%
}
to {
background-position: 187% 0%
}
}
#content {
width: 100%;
height: 300px;
background: url(http://www.gstatic.com/webp/gallery/1.jpg) 0% 0% repeat;
text-align: center;
font-size: 26px;
color: #000;
-webkit-animation-name: MOVE-BG;
-webkit-animation-duration: 100s;
-webkit-animation-timing-function: linear;
-webkit-animation-iteration-count: infinite;
}
我已经研究了好几个小时了,但找不到任何可以在子像素级别缓慢而流畅地制作动画的东西。我当前的示例是根据此页面上的示例代码制作的:http://css-tricks.com/parallax-background-css3/
可以在此页面的 translate() 示例中看到我所追求的动画流畅度:
http://css-tricks.com/tale-of-animation-performance/
如果不能用背景位置来完成,有没有办法用多个 div 伪造重复背景并使用翻译移动这些 div?
最佳答案
检查这个例子:
#content {
height: 300px;
text-align: center;
font-size: 26px;
color: #000;
position:relative;
}
.bg{
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
z-index: -1;
background: url(http://www.gstatic.com/webp/gallery/1.jpg) 0% 0% repeat;
animation-name: MOVE-BG;
animation-duration: 100s;
animation-timing-function: linear;
animation-iteration-count: infinite;
}
@keyframes MOVE-BG {
from {
transform: translateX(0);
}
to {
transform: translateX(-187%);
}
}
<div id="content">Foreground content
<div class="bg"></div>
</div>
关于css - 使用平滑结果动画 CSS 背景位置(子像素动画),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21087518/