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了解吗?有使用过吗?请说一下使用场景。 #768

Open
pwstrick opened this issue Jul 18, 2019 · 1 comment
Labels
JavaScript JavaScript类的题目

Comments

@pwstrick
Copy link
Owner

前端的requestAnimationFrame了解吗?有使用过吗?请说一下使用场景。

来源《一个前端失业者的面试之旅

@pwstrick pwstrick added the JavaScript JavaScript类的题目 label Jul 18, 2019
@pwstrick
Copy link
Owner Author

当显示器将一帧画面绘制完成后,并在准备读取下一帧之前,显示器会发出一个垂直同步信号(Vertical Synchronization)给 GPU,简称 VSync。
CSS 动画是由渲染进程自动处理的(在合成线程中单独处理),所以渲染进程会让 CSS 渲染每帧动画的过程与 VSync 的时钟保持一致, 这样就能保证 CSS 动画的高效率执行。
但是 JavaScript 是由用户控制的,如果采用 setTimeout 来触发动画每帧的绘制,那么其绘制时机是很难和 VSync 时钟保持一致的,所以 JavaScript 中又引入了 window.requestAnimationFrame,用来和 VSync 的时钟周期同步,它的回调任务会在每一帧的开始执行。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JavaScript JavaScript类的题目
Projects
None yet
Development

No branches or pull requests

1 participant