使用平滑结果(子像素动画)动画化CSS背景位置 [英] Animate CSS background-position with smooth results (sub-pixel animation)
问题描述
我试图动画的div的背景位置,慢慢,但没有它的动作。您可以在这里查看我目前努力的结果:
I'm trying to animate the background-position of a div, slowly, but without it having jerky movement. You can see the result of my current efforts here:
http:// jsfiddle .net / 5pVr4 / 2 /
@-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 /
I have been at this for hours and can't find anything that will animate slowly and smoothly at a sub-pixel level. My current example was made from the example code on this page: http://css-tricks.com/parallax-background-css3/
在此页面的translate()示例中可以看到我所处理的动画的平滑度:
The smoothness of animation I'm after can be seen on this page's translate() example:
http://css-tricks.com/tale-of-animation-performance/
如果不能使用background-position,是否有一种方法来伪造具有多个div的重复背景,并使用translate? / p>
If it can't be done with the background-position, is there a way to fake the repeating background with multiple divs and move those divs using translate?
推荐答案
检查此示例:
<div id="content">Foreground content
<div class="bg"></div>
</div>
@-webkit-keyframes MOVE-BG {
from {
-webkit-transform: translateX(0);
}
to {
-webkit-transform: translateX(-187%);
}
}
#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;
-webkit-animation-name: MOVE-BG;
-webkit-animation-duration: 100s;
-webkit-animation-timing-function: linear;
-webkit-animation-iteration-count: infinite;
}
这篇关于使用平滑结果(子像素动画)动画化CSS背景位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!