diff --git a/assets/js/main.js b/assets/js/main.js index 1d5fedf..20bdd2c 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -88,7 +88,12 @@ var start = null; function step(ts) { - if (start === null) start = ts; + if (start === null) { + // ปล่อยค่าใน HTML ไว้ก่อนจนเฟรมแรกมาถึง + start = ts; + requestAnimationFrame(step); + return; + } var t = Math.min(1, (ts - start) / duration); var eased = 1 - Math.pow(1 - t, 3); el.textContent = formatNumber(target * eased, dec) + suffix; @@ -119,15 +124,13 @@ /* เรียกทั้งสองตัวเมื่อเลื่อน/ย่อขยาย และครั้งแรกหลังโหลด */ var ticking = false; - function onFrame() { - checkReveals(); - checkCounters(); - ticking = false; - } function requestCheck() { if (ticking) return; ticking = true; - window.requestAnimationFrame(onFrame); + // ตรวจทันที ไม่รอ rAF — กันกรณีเฟรมไม่เดิน (แท็บพื้นหลัง/เครื่องช้า) + checkReveals(); + checkCounters(); + ticking = false; } window.addEventListener("scroll", requestCheck, { passive: true }); window.addEventListener("resize", requestCheck, { passive: true }); diff --git a/index.html b/index.html index da9fba9..f24656f 100644 --- a/index.html +++ b/index.html @@ -95,10 +95,10 @@