1 回答

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超13個(gè)贊
requestAnimationFrame是一個(gè)只執(zhí)行一次的函數(shù),具體的執(zhí)行時(shí)間由瀏覽器決定,基本上是瀏覽其執(zhí)行下一次paint的時(shí)刻。
var before = null;
requestAnimationFrame(function animate(now) {
var c = earth.getPosition();
elapsed = before? now - before: 0;
before = now;
earth.setCenter([c[0], c[1] + 0.1*(elapsed/30)]);
if(before){//加入自己的判斷邏輯,決定在下一次repaint時(shí)是否執(zhí)行
requestAnimationFrame(animate);
}
});
添加回答
舉報(bào)