0

I'm wondering whether there is a proper way to pause requestAnimationFrame animations when the user has scrolled and the animation is not in the view anymore?

requestAnimationFrame does this automatically when the browser displays another tab, but is it possible to do it when the user scrolls?

4

1 回答 1

0

唯一的方法是将你的代码分成小函数块。

当您向下滚动时,请跟踪正在完成多少滚动。

您可以提供自己的自定义条件,并在函数已执行且未获得焦点后使用window.cancelAnimationFrame() 。

于 2013-07-15T19:28:49.583 回答