Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

requestAnimationFrame #70

Open
xiaochengzi6 opened this issue Dec 1, 2022 · 0 comments
Open

requestAnimationFrame #70

xiaochengzi6 opened this issue Dec 1, 2022 · 0 comments

Comments

@xiaochengzi6
Copy link
Owner

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant