javascript - requestAnimationFrame 填充 : what's the element parameter for?

标签 javascript parameters element requestanimationframe

我正在使用 Erik Möller 的 requestAnimationFrame polyfill(由 Paul Irish 和 Tino Zijdel 修复),我想知道第二个参数“element”的用途是什么。

这是代码:

(function() {
    var lastTime = 0;
    var vendors = ['ms', 'moz', 'webkit', 'o'];
    for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
        window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
        window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
                                   || window[vendors[x]+'CancelRequestAnimationFrame'];
    }

    if (!window.requestAnimationFrame)
        window.requestAnimationFrame = function(callback, element) {
            var currTime = new Date().getTime();
            var timeToCall = Math.max(0, 16 - (currTime - lastTime));
            var id = window.setTimeout(function() { callback(currTime + timeToCall); },
              timeToCall);
            lastTime = currTime + timeToCall;
            return id;
        };

    if (!window.cancelAnimationFrame)
        window.cancelAnimationFrame = function(id) {
            clearTimeout(id);
        };
}());

所以我的问题是关于这一行的:

window.requestAnimationFrame = function(callback, element) {

“元素”有什么作用?

提前非常感谢您,

最佳答案

根据W3C draft ,没有 element 参数传递给此函数。至少现在是这样。

如您所见,有 an issue这建议添加这样的参数。 此问题被认为对于本规范的第一个版本来说不是必需的。并且已被关闭。

我认为你可以忽略这个参数。

关于javascript - requestAnimationFrame 填充 : what's the element parameter for?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16217351/

相关文章:

javascript - react 组件已卸载

MySQL存储过程在参数中传递数字数组

c - 链排序 - 当我增加元素数量时,对数组进行排序不起作用

c++ - 初始化矩阵

templates - Teamcity - 从模板中强制配置配置参数

XPath:可以选择什么?

javascript - 使用 React、Rails 和 Paperclip 进行 AJAX 图像上传

javascript - 移动菜单在 Jsfiddle 中有效,但在本地主机上无效

javascript - NodeJs : can't write a file

c++ - const 参数不够 const