javascript - 为什么 requestAnimationFrame 函数接受一个元素作为参数?

标签 javascript html html5-canvas html5-animation requestanimationframe

我只是想了解为什么 window.requestAnimationFrame 接受第二个参数作为元素,这背后的原因是什么?

我很想知道这个函数的底层执行....

最佳答案

添加它是为了当元素不在 View 中时(例如由于滚动),动画不会运行。

来自 the specs :

Editorial note

ISSUE-4 Do we want to allow an Element to be passed to requestAnimationFrame, so that animations affecting the given element are throttled or paused when scrolled out of view?

关于这个问题的更多信息可以found here .

关于javascript - 为什么 requestAnimationFrame 函数接受一个元素作为参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7487691/

相关文章:

javascript - 过滤对象数组中的 bool 值

javascript - 使用 angular js 客户端对 Python 服务器进行 rest 调用的示例

javascript - Polymer 1.x dom-repeat 无法正常工作

javascript - jQuery ajaxForm 完整版有时有效,有时它只触发 native JavaScript 函数然后停止

JavaScript、 Canvas : Calculating the angle from a flying bubble

javascript - 从 Node 请求 Elasticsearch 超时

html - 侧边栏随机从左跳到右,不记得触摸 CSS

javascript 未在页面上加载

javascript - 窗口大小调整后 HTML5 Canvas 被阻止

javascript - HTML Canvas 矩形内的阴影效果