xiaochengzi6 / Blog

个人博客
GNU Lesser General Public License v2.1
0 stars 0 forks source link

requestAnimationFrame #70

Open xiaochengzi6 opened 1 year ago

xiaochengzi6 commented 1 year ago

requestAnimationFrame 会用于在浏览器下一次重绘前调用回调函数,会在回调函数的参数中传入DOMHighResTimeStamp数值,(double类型用于存储毫秒级的时间值)

let current = 0
function callback(timeStamp){
  const step = timeStamp - current
  if(step > 30) return 

  window.requestAnimationFrame(callback)
} 

它的返回值是一个 long整数,没有特别含义在整个回调列表中是唯一的可做清除回调的标记

const id = requrestAnimationFrame(callback)
// 停止回调函数的调用
cancelAnimationFrame(id)

相关文章

  1. requestAnimationFrame 机制 -伢羽
  2. MDN介绍
  3. 拓展阅读performance