Javascript window.requestAnimationFrame()是如何工作的?

Javascript window.requestAnimationFrame()是如何工作的?,javascript,Javascript,我如何理解以下代码?我对JavaScript有点陌生 var start = null; var element = document.getElementById('SomeElementYouWantToAnimate'); element.style.position = 'absolute'; function step(timestamp) { if (!start) start = timestamp; var progress = timestamp - sta

我如何理解以下代码?我对JavaScript有点陌生

var start = null;
var element = document.getElementById('SomeElementYouWantToAnimate');
element.style.position = 'absolute';

function step(timestamp) {
   if (!start) start = timestamp;
      var progress = timestamp - start;
      element.style.left = Math.min(progress / 10, 200) + 'px';
   if (progress < 2000) {
      window.requestAnimationFrame(step);
   }
}

window.requestAnimationFrame(step);
var start=null;
var element=document.getElementById('SomeElementYouWantToAnimate');
element.style.position='absolute';
功能步骤(时间戳){
如果(!start)start=时间戳;
var progress=时间戳-开始;
element.style.left=Math.min(progress/10200)+“px”;
如果(进度<2000年){
window.requestAnimationFrame(步骤);
}
}
window.requestAnimationFrame(步骤);
我在这里得到一段代码:

我想问的是关于
函数步骤(timestamp){…}
上的
时间戳
参数的问题

我不明白这个
时间戳如何得到值,为什么?

因为我看不到分配的任何值。

requestAnimationFrame
函数中,有一个看起来很模糊的东西:

function requestAnimationFrame(func) {
    waitForNextAnimationFrame();
    func(getCurrentTime());
}

发生的情况是,
requestAnimationFrame
将您的函数作为输入,然后,稍后,使用参数调用它。

requestAnimationFrame
将调用传递的回调,并在当前时间内传递。从链接的文档中:
一个参数,指定在下次重新绘制时更新动画时要调用的函数。回调只有一个参数DOMHighResTimeStamp,它指示requestAnimationFrame()启动回调的当前时间(从performance.now()返回的时间)。
这是一个参数。它从参数中获取其值,函数在参数中被调用-在
requestAnimationFrame
中@Bergi不认为op理解rAF会自动将其传递给回调函数。“我不理解这个时间戳是如何获取值的,为什么?”与任何函数获取其参数值的方式相同:它由浏览器内部的函数调用方提供。