在scroll
事件中使用window.requestAnimationFrame
时,我遇到了问题。
我想要使用CSS transform:translate3D
来移动一个DIV
。
document.getElementById("content").addEventListener("scroll", function(){
var getScroll = this.scrollTop * 1.2;
function repeatOften() {
document.getElementById("moveable").style.transform =
"translate3D(0," + getScroll + "px, 0)";
requestAnimationFrame(repeatOften);
}
requestAnimationFrame(repeatOften);
});
这里有一个示例:https://jsfiddle.net/tcayv8dp/
为什么这个动画运行不流畅?我的代码哪里出了问题?
谢谢!