requestAnimationFrame API , 顾名思义,请求动画帧,也称 帧循环。
浏览器刷新每一帧的时候都会执行 API 内的回调函数
返回值
一个 long 整数,请求 ID ,是回调列表中唯一的标识。是个非零值,没别的意义。
(() => {const beginBtn = document.querySelector("#begin")const endBtn = document.querySelector("#end")let myRef;beginBtn.addEventListener("click", () => {myRef = requestAnimationFrame(test)})endBtn.addEventListener("click", () => {cancelAnimationFrame(myRef) // 取消帧循环})function test() {myRef = requestAnimationFrame(test)console.log('🚀🚀~ myRef:', myRef);}})()
