fix(motion): คืนอนิเมชัน reveal ที่หายไป + จดข้อยกเว้นเบราว์เซอร์
สาเหตุ: hydration เขียนทับ class ของ <html> ทำให้ `fx-motion` หลุด และอนิเมชันเดิมผูกกับคลาสนั้นอย่างเดียว → อนิเมชันหายทั้งเว็บ - ผูก "ตัวอนิเมชัน" กับ @media (prefers-reduced-motion: no-preference) (สถานะซ่อนก่อน reveal ยังผูกกับ html.fx-motion เพื่อกันเนื้อหาหายเมื่อปิด JS) - เพิ่ม <MotionBootstrap/> เติมคลาส fx-motion ซ้ำหลัง hydration + ฟังการเปลี่ยน reduced-motion - คืน @keyframes fx-swap-in ที่หลุดไประหว่างแก้ CSS - DESIGN.md: Motion contract สองชั้น + ตารางข้อยกเว้นต่อเบราว์เซอร์ (scrollbar/share/install/blur/ฟอนต์ไทย/ITP) - sw VERSION v2.0.4
This commit is contained in:
1 parent
2eb625c8bc
commit
cfb24b8138
4 files changed
+92
-40
No files matched your search
+46
-37
@@ -400,31 +400,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
/* สถานะตั้งต้น: ซ่อนเฉพาะเมื่อ motion เปิดอยู่ (JS ใส่คลาสแล้วเท่านั้น) */
|
||||
html.fx-motion [data-reveal] {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
html.fx-motion [data-reveal="rise"][data-revealed] {
|
||||
animation: fx-rise-in var(--fx-slow) var(--fx-ease-out) var(--fx-delay, 0ms)
|
||||
both;
|
||||
}
|
||||
|
||||
html.fx-motion [data-reveal="fade"][data-revealed] {
|
||||
animation: fx-fade-in var(--fx-base) var(--fx-ease-out) var(--fx-delay, 0ms)
|
||||
both;
|
||||
}
|
||||
|
||||
html.fx-motion [data-reveal="zoom"][data-revealed] {
|
||||
animation: fx-pop-in var(--fx-slow) var(--fx-ease-out) var(--fx-delay, 0ms)
|
||||
both;
|
||||
}
|
||||
|
||||
/* อนิเมชันตอนโหลด (ไม่ผูกกับ scroll) */
|
||||
html.fx-motion .fx-page {
|
||||
animation: fx-page-in var(--fx-page) var(--fx-ease-out) both;
|
||||
}
|
||||
|
||||
/* สลับภาพในแกลเลอรี (ปุ่มลูกศร) — จางเข้าเบา ๆ ไม่กระตุก */
|
||||
@keyframes fx-swap-in {
|
||||
from {
|
||||
@@ -437,25 +412,59 @@ html.fx-motion .fx-page {
|
||||
}
|
||||
}
|
||||
|
||||
html.fx-motion .fx-swap {
|
||||
animation: fx-swap-in 320ms var(--fx-ease-out) both;
|
||||
/* ══ สถานะตั้งต้น + อนิเมชัน reveal ══════════════════════════════════════
|
||||
กันสองทาง:
|
||||
1) เนื้อหาห้ามหายถ้าปิด JS → สถานะ "ซ่อน" ผูกกับคลาส `html.fx-motion`
|
||||
(คลาสถูกใส่โดยสคริปต์ใน <head> และเสริมอีกครั้งจาก client effect)
|
||||
2) อนิเมชันต้องทำงานแม้คลาสหลุด (เคยเกิดจาก hydration ลบคลาส) → ตัวอนิเมชัน
|
||||
ผูกกับ `@media (prefers-reduced-motion: no-preference)` แทน
|
||||
ผลคือทุกเอนจิน (Chromium / Firefox / Safari) ได้อนิเมชันเหมือนกัน และ
|
||||
ผู้ใช้ที่ขอ reduced motion ได้เนื้อหานิ่งครบทันที */
|
||||
html.fx-motion [data-reveal] {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
html.fx-motion .fx-drop {
|
||||
animation: fx-drop-in var(--fx-base) var(--fx-ease-out) both;
|
||||
}
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
[data-reveal="rise"][data-revealed] {
|
||||
animation: fx-rise-in var(--fx-slow) var(--fx-ease-out) var(--fx-delay, 0ms)
|
||||
both;
|
||||
}
|
||||
|
||||
html.fx-motion .fx-hero-image {
|
||||
animation: fx-hero-zoom 1400ms var(--fx-ease-out) both;
|
||||
[data-reveal="fade"][data-revealed] {
|
||||
animation: fx-fade-in var(--fx-base) var(--fx-ease-out) var(--fx-delay, 0ms)
|
||||
both;
|
||||
}
|
||||
|
||||
[data-reveal="zoom"][data-revealed] {
|
||||
animation: fx-pop-in var(--fx-slow) var(--fx-ease-out) var(--fx-delay, 0ms)
|
||||
both;
|
||||
}
|
||||
|
||||
/* อนิเมชันตอนโหลด (ไม่ผูกกับ scroll) */
|
||||
.fx-page {
|
||||
animation: fx-page-in var(--fx-page) var(--fx-ease-out) both;
|
||||
}
|
||||
|
||||
.fx-swap {
|
||||
animation: fx-swap-in 320ms var(--fx-ease-out) both;
|
||||
}
|
||||
|
||||
.fx-drop {
|
||||
animation: fx-drop-in var(--fx-base) var(--fx-ease-out) both;
|
||||
}
|
||||
|
||||
.fx-hero-image {
|
||||
animation: fx-hero-zoom 1400ms var(--fx-ease-out) both;
|
||||
}
|
||||
}
|
||||
|
||||
/* ทางออกสุดท้าย: ถ้าผู้ใช้ขอ reduced motion ให้ทุกอย่างนิ่งและเห็นครบ */
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
html.fx-motion [data-reveal],
|
||||
html.fx-motion .fx-page,
|
||||
html.fx-motion .fx-drop,
|
||||
html.fx-motion .fx-swap,
|
||||
html.fx-motion .fx-hero-image {
|
||||
[data-reveal],
|
||||
.fx-page,
|
||||
.fx-drop,
|
||||
.fx-swap,
|
||||
.fx-hero-image {
|
||||
animation: none !important;
|
||||
opacity: 1 !important;
|
||||
transform: none !important;
|
||||
|
||||
@@ -124,6 +124,28 @@ function ServiceWorkerSetup() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* เติมคลาส `fx-motion` ซ้ำฝั่ง client
|
||||
*
|
||||
* ทำไมต้องมี: สคริปต์ใน <head> ใส่คลาสนี้ก่อน paint แล้ว แต่พบว่า hydration
|
||||
* เขียนทับ `class` ของ <html> ทำให้คลาสหลุด → เนื้อหาที่ควร "ค่อย ๆ โผล่"
|
||||
* กลายเป็นโผล่ทันที (อนิเมชันหาย) · effect นี้รันหลัง hydration จึงเติมกลับให้เสถียร
|
||||
* ตัวอนิเมชันเองผูกกับ `@media (prefers-reduced-motion: no-preference)` แล้ว
|
||||
* จึงยังทำงานได้แม้คลาสหลุด (คลาสมีหน้าที่แค่ "ซ่อนก่อน reveal" ไม่ให้กระพริบ)
|
||||
*/
|
||||
function MotionBootstrap() {
|
||||
useEffect(() => {
|
||||
const query = window.matchMedia("(prefers-reduced-motion: reduce)");
|
||||
const sync = () => {
|
||||
document.documentElement.classList.toggle("fx-motion", !query.matches);
|
||||
};
|
||||
sync();
|
||||
query.addEventListener("change", sync);
|
||||
return () => query.removeEventListener("change", sync);
|
||||
}, []);
|
||||
return null;
|
||||
}
|
||||
|
||||
export default function Root() {
|
||||
const [queryClient] = useState(() => createAgentNativeQueryClient());
|
||||
const { content, localeFromUrl, shareOrigin } =
|
||||
@@ -141,6 +163,7 @@ export default function Root() {
|
||||
<AppProviders queryClient={queryClient}>
|
||||
<DbSyncSetup />
|
||||
<ServiceWorkerSetup />
|
||||
<MotionBootstrap />
|
||||
<AppLayout>
|
||||
<Outlet />
|
||||
</AppLayout>
|
||||
|
||||
Reference in new issue
Block a user