fix(js): synchronous reveal/counter checks, real values in HTML
- ตรวจ reveal/counter แบบ sync (ไม่พึ่ง rAF ที่อาจไม่เดิน) - ใส่ค่าจริงใน HTML (84 / 190 / 5.6 / 270,000+) เพื่อให้อ่านได้แม้ JS ไม่ทำงาน - countUp ไม่ทับค่าด้วย 0 ก่อนเฟรมแรกมาถึง - bump script เป็น ?v=9
This commit is contained in:
1 parent
3dcbdb88e7
commit
cf48d0edad
2 files changed
+17
-14
No files matched your search
+10
-7
@@ -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 });
|
||||
|
||||
Reference in new issue
Block a user