javascript - 速率高于 60 fps 的 requestAnimationFrame

标签 javascript

来自 MDN , 我有这个:

Be sure to always use the first argument (or some other method for getting the current time) to calculate how much the animation will progress in a frame, otherwise the animation will run faster on high refresh rate screens.


有了这个,我可以假设使用 144hz 显示器,例如,我可以有 requestAnimationFrame运行速度超过 60 fps?

最佳答案

完全正确。
这是一个简单的测量示例:

let i = 0;
const start = Date.now();
const stop = start + 5000;

function raf() {
  requestAnimationFrame(() => {
    const now = Date.now();
    if (now < stop){
      i++;
      raf();
    }else{
      const elapsedSeconds = (now - start) / 1000;
      console.log('Frame rate is: %f fps', i / elapsedSeconds);
    }
  });
}

console.log('Testing frame rate...')
raf();

在我的机器上,它显示 143.7401178670024。我正在使用 144HZ 显示器。

关于javascript - 速率高于 60 fps 的 requestAnimationFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64955584/

相关文章:

javascript - 当提供箭头函数时,Array.prototype.forEach 中的 'this' 如何解析?

javascript - Socket.io 无法连接,求助于 "polling"

javascript - 当使用 Javascript 调整屏幕大小时覆盖样式(由之前的函数给出)

javascript - JSFiddle 上的 AngularJS

javascript - 使用 Google Contacts API v3 仅列出 "My Contacts"组的联系人

javascript - 如何使用 jQuery 使 div 的边距左边 = 宽度的一半?

javascript - 套接字 IO 重新连接?

javascript - Angularjs - 复选框 - 计算多个选定/未选定的项目

javascript - 正则表达式表示仅重复我提供的字符的单词?

Javascript 在下拉列表上设置默认值不起作用