本文介绍了动画与流畅的效果(子像素动画)CSS背景位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图动画的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:
@-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;
}
我已经在这几个小时,也找不到任何将缓慢平滑的动画在子像素级别。我现在的例子就是从这个页面上的例子code制成:http://css-tricks.com/parallax-background-css3/
动画的平滑度可以在此页面的翻译()的例子可以看出以后我:
The smoothness of animation I'm after can be seen on this page's translate() example:
http://css-tricks.com/tale-of-animation-performance/
如果它不能与背景位置做的,是有办法伪造重复背景与多个div使用翻译这些div移动?
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背景位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!