假设你有一个无限循环的背景图像,我看到用CSS3简单的动画消耗了我PC内存的50%,但是很多,但是还没有尝试使用jQuery。
你有什么困难?哪一个消耗更少的PC内存?
这是我的Webkit CSS3代码:
.stars_back {
background: url('stars.png') repeat; position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: -10;
-webkit-animation-name: star-back; -webkit-animation-duration: 1700s;
-webkit-animation-timing-function: linear; -webkit-animation-iteration-count: infinite;
}
@-webkit-keyframes star-back {
from { background-position: 1000% 5% }
to { background-position: 5% 5% }
}
答案 0 :(得分:2)
动画背景图像效率不高,无论是jQuery还是CSS转换都无关紧要。我建议你添加一个包含背景图像的额外元素来应用硬件加速:
.stars_back {
/* right: 100% forces the div to be twice the intended width, parent should have overflow: hidden */
background: url('stars.png') repeat; position: absolute; top: 0; left: 0; right: 100%; bottom: 0; z-index: -10;
-webkit-animation-name: star-back; -webkit-animation-duration: 1700s;
-webkit-animation-timing-function: linear; -webkit-animation-iteration-count: infinite;
}
@-webkit-keyframes star-back {
/* translate3d(-50%,0,0) puts the second half of the div in the viewport and then repeats*/
from { -webkit-transform: translate3d(0,0,0) }
to { -webkit-transform: translate3d(-50%,0,0) }
}