js requestAnimationFrame 每秒执行一次
let count = 0, maxCount = 3;
function event() {
count += 1;
console.log(count);
return count < maxCount;
}
let prev = 0;
const t = 1000; // 1秒
function anime(timestamp) {
const elapsed = timestamp - prev;
if (elapsed > t) {
if (!event()) return;
prev = timestamp;
}
requestAnimationFrame(anime);
}
requestAnimationFrame(anime);