求助帖:requestAnimationFrame嵌套问题

74 阅读1分钟
        btn.onclick = function () {
            requestAnimationFrame(() => {
                let date1 = Date.now();
                console.log('requestAnimationFrame1');
                requestAnimationFrame(() => {
                    console.log('requestAnimationFrame2');
                    let date2 = Date.now();
                    console.log(date2 - date1); // 0~9 每次点击按钮打印都不固定,为啥不是间隔16ms呢?
                });
            });
        }

有没有懂渲染流程的大佬,告诉我,为啥两次requestAnimationFrame的回调间隔这么短? 难道是因为它们同时被执行了?第二个回调,并没有放入下一个帧中去执行吗?