From 2950295690a731559069493ae6dd06eb33ca9641 Mon Sep 17 00:00:00 2001 From: Bkk1234 Date: Thu, 19 Nov 2026 01:10:27 +0700 Subject: [PATCH] feat(motion): scroll-reveal and cinematic entrance animations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - motion.css / motion.js: reveal-on-scroll (IntersectionObserver), hero word-by-word entrance, drifting warm orbs, sheen on primary CTA, section underline sweep, scroll progress bar, count-up numbers - content never hidden unless .fx-motion: JS off or reduced-motion shows everything - hover lift moved to the translate property so reveal keyframes cannot override it - re-call initReveal after grid re-render and admin re-mount; SW precache + VERSION bump - docs: DESIGN.md §9 motion contract, AGENTS.md pitfalls --- AGENTS.md | 1 + DESIGN.md | 26 ++++ assets/css/home.css | 3 +- assets/css/motion.css | 298 ++++++++++++++++++++++++++++++++++++++++++ index.html | 17 ++- sw.js | 4 +- ui/app.js | 4 + ui/motion.js | 133 +++++++++++++++++++ ui/views/admin.js | 9 +- ui/views/home.js | 20 ++- 10 files changed, 503 insertions(+), 12 deletions(-) create mode 100644 assets/css/motion.css create mode 100644 ui/motion.js diff --git a/AGENTS.md b/AGENTS.md index 94f1e6b..36f5c9e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -77,3 +77,4 @@ curl -s localhost:8090/api/projects | head -5 - `PUT api/projects` เขียนทับทั้งไฟล์: ส่งข้อมูลที่ normalize แล้วเท่านั้น ไม่งั้นคีย์จะหาย - กดเผยแพร่ซ้ำโดยไม่แก้อะไรจะได้ commit ใหม่ (เพราะ `updated_at` เปลี่ยน) — ปกติ ไม่ใช่บั๊ก - ถ้าเปิดเว็บด้วย `python -m http.server` API จะ 404 → หน้าหลังบ้านจะขึ้นสถานะ “เปิดแบบไฟล์นิ่ง” และใช้ดาวน์โหลด JSON แทน +- **Motion**: ทุกครั้งที่สร้าง DOM ใหม่ (กรองคำค้นหา, `mount()` ของ admin) ต้องเรียก `initReveal(...)` ใหม่ ไม่งั้น element ค้าง `opacity: 0`; hover ยกการ์ดต้องใช้ `translate` ไม่ใช่ `transform`; ถ้าวัดผลในแท็บเบื้องหลัง IO/rAF จะไม่ทำงาน ให้ `Page.bringToFront` ก่อนสรุปว่าโค้ดพัง (รายละเอียดใน `DESIGN.md` §9) diff --git a/DESIGN.md b/DESIGN.md index be19bae..05418d1 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -73,3 +73,29 @@ - ไอคอน PNG จริง 192 / 512 / 512-maskable / 180 (สร้างจาก `make_icons` ด้วย PIL ไม่ใช้ตัวอักษร) - `sw.js`: network-first สำหรับ HTML/CSS/JS/JSON, cache-first สำหรับรูป/ฟอนต์, ข้าม `/api/` - แก้ `sw.js` หรือรายการ `PRECACHE` → ต้อง bump `VERSION` และ `` พร้อมกัน + +## 9. Motion (ลูกเล่นภาพเคลื่อนไหว) + +ไฟล์: `assets/css/motion.css` + `ui/motion.js` + +**สัญญาความปลอดภัยของเนื้อหา** — ห้ามซ่อนเนื้อหาใน CSS หลัก: +- inline script ใน `` ใส่ `.fx-motion` ที่ `` ก่อนวาดเฟรมแรก เว้นแต่ผู้ใช้ตั้ง `prefers-reduced-motion: reduce` +- CSS ซ่อนเฉพาะ `html.fx-motion [data-reveal]`; เมื่อ JS ปิด/ถูกบล็อก/ลดการเคลื่อนไหว → เนื้อหาเห็นครบ ไม่มีช่วงจอว่าง +- ทุก keyframe มีคู่หูใน `@media (prefers-reduced-motion: reduce)` ที่สั่ง `animation: none; opacity: 1; transform: none` + +**อนิเมตได้เฉพาะ `transform` / `opacity` / `filter`** — ห้ามอนิเมต `width` / `height` / `top` + +| องค์ประกอบ | ท่า | เวลา | +|---|---|---| +| ชื่อเรื่องฮีโร่ | แยกเป็นคำ (`splitWordsHtml` ตัดด้วยช่องว่างเท่านั้น ปลอดภัยกับสระ/วรรณยุกต์ไทย) ยกขึ้น + คลายเบลอ | 760ms · เริ่ม 140ms · เว้น 85ms/คำ | +| ป้ายเหนือหัวเรื่อง / คำโปรย / ช่องค้นหา / แถบข้อมูล | drop / rise / pop / fade ตามลำดับ | 520–760ms | +| การ์ดลอยในฮีโร่ | สไลด์จากซ้าย ทีละใบ | 700ms · 320/440/560ms | +| การ์ดโปรเจค | `data-reveal="pop"` ตอนเลื่อนถึง (IntersectionObserver, `rootMargin: 2000px 0px -6% 0px`) | 660ms · หน่วง 95ms × คอลัมน์ | +| หัวข้อ section | เส้นใต้กวาดจากซ้าย (`scaleX`) | 760ms | +| แถบความคืบหน้า | `scaleX` ตาม scroll ผ่าน rAF | — | + +**กับดักที่ต้องจำ** +- การ์ดที่สร้างใหม่ (กรองคำค้นหา) ต้องเรียก `initReveal(gridEl)` ซ้ำ ไม่งั้นค้างที่ `opacity: 0` +- `mount()` ของหน้า admin ถูกเรียกซ้ำ (กด “ทิ้งการแก้ไข”) → ต้องเรียก `initReveal(root)` ทุกครั้ง +- hover ยกการ์ดใช้พร็อพเพอร์ตี `translate` (ไม่ใช่ `transform`) เพราะ `animation-fill-mode: both` ของ reveal จะทับ `transform` +- แท็บที่อยู่เบื้องหลัง: IntersectionObserver ไม่ยิงและ rAF หยุด — อย่าด่วนสรุปว่าโค้ดพัง ให้ยกแท็บขึ้นหน้าก่อนวัด diff --git a/assets/css/home.css b/assets/css/home.css index 7d7181f..c3ad3f6 100644 --- a/assets/css/home.css +++ b/assets/css/home.css @@ -279,7 +279,8 @@ .project-card:focus-within { border-color: var(--brand-300); box-shadow: var(--shadow-md); - transform: translateY(-2px); + /* ใช้ translate (คนละพร็อพเพอร์ตีกับ transform) เพื่อไม่ชนกับคีย์เฟรม reveal */ + translate: 0 -3px; } .project-card__top { display: flex; diff --git a/assets/css/motion.css b/assets/css/motion.css new file mode 100644 index 0000000..0fa4ac5 --- /dev/null +++ b/assets/css/motion.css @@ -0,0 +1,298 @@ +/* ========================================================================== + motion.css — ลูกเล่นภาพเคลื่อนไหว + สัญญา: ซ่อนเนื้อหาเฉพาะเมื่อ มีคลาส .fx-motion (JS ใส่ให้) + ถ้า JS ปิด/บล็อก หรือผู้ใช้ตั้ง reduced-motion → เนื้อหาทั้งหมดเห็นปกติทันที + อนิเมตเฉพาะ transform / opacity / filter เท่านั้น + ========================================================================== */ + +/* --------------------------------------------------- แถบความคืบหน้าการเลื่อน */ +.scroll-progress { + position: fixed; + inset-block-start: 0; + inset-inline: 0; + height: 3px; + z-index: 25; + background: transparent; + pointer-events: none; +} +.scroll-progress__bar { + display: block; + height: 100%; + transform-origin: 0 50%; + transform: scaleX(0); + background: linear-gradient(90deg, var(--brand-500), var(--brand-700) 55%, var(--brand-900)); + opacity: 0; + transition: opacity 240ms var(--ease); +} +html.fx-motion .scroll-progress__bar { + opacity: 0.95; +} + +/* ------------------------------------------------------------ keyframes */ +@keyframes fx-word-in { + from { + opacity: 0; + transform: translate3d(0, 0.55em, 0) scale(0.97); + filter: blur(5px); + } + to { + opacity: 1; + transform: none; + filter: none; + } +} +@keyframes fx-drop-in { + from { + opacity: 0; + transform: translate3d(0, -14px, 0); + } + to { + opacity: 1; + transform: none; + } +} +@keyframes fx-rise-in { + from { + opacity: 0; + transform: translate3d(0, 26px, 0) scale(0.985); + } + to { + opacity: 1; + transform: none; + } +} +@keyframes fx-pop-in { + from { + opacity: 0; + transform: scale(0.92); + } + to { + opacity: 1; + transform: none; + } +} +@keyframes fx-fade-in { + from { + opacity: 0; + } + to { + opacity: 1; + } +} +@keyframes fx-slide-in { + from { + opacity: 0; + transform: translate3d(-22px, 0, 0); + } + to { + opacity: 1; + transform: none; + } +} +@keyframes fx-orb-a { + from { + transform: translate3d(0, 0, 0) scale(1); + } + to { + transform: translate3d(-38px, 46px, 0) scale(1.12); + } +} +@keyframes fx-orb-b { + from { + transform: translate3d(0, 0, 0) scale(1.05); + } + to { + transform: translate3d(48px, -30px, 0) scale(0.94); + } +} +@keyframes fx-sheen { + from { + transform: translate3d(-140%, 0, 0) rotate(12deg); + } + to { + transform: translate3d(240%, 0, 0) rotate(12deg); + } +} + +/* ---------------------------------------------------- ฮีโร่: เข้าฉากแบบหนัง */ +html.fx-motion .hero__eyebrow { + animation: fx-drop-in 520ms var(--ease) 60ms both; +} +html.fx-motion .hero__lead { + animation: fx-rise-in 620ms var(--ease) 520ms both; +} +html.fx-motion .searchbar { + animation: fx-pop-in 680ms cubic-bezier(0.16, 0.84, 0.28, 1) 600ms both; +} +html.fx-motion .hero__meta { + animation: fx-fade-in 620ms var(--ease) 760ms both; +} +html.fx-motion .hero__deco-card { + animation: fx-slide-in 700ms var(--ease) both; +} +html.fx-motion .hero__deco-card:nth-child(1) { + animation-delay: 320ms; +} +html.fx-motion .hero__deco-card:nth-child(2) { + animation-delay: 440ms; +} +html.fx-motion .hero__deco-card:nth-child(3) { + animation-delay: 560ms; +} + +/* คำในหัวเรื่อง: เลื่อนเข้ามาทีละคำ */ +.fx-word { + display: inline-block; +} +.fx-word > span { + display: inline-block; +} +html.fx-motion .fx-word > span { + animation: fx-word-in 760ms cubic-bezier(0.16, 0.84, 0.28, 1) both; + animation-delay: var(--fx-delay, 0ms); +} + +/* แสงอบอุ่นด้านหลังฮีโร่ — เคลื่อนช้า ๆ */ +.hero__ambience { + position: absolute; + inset: 0; + overflow: hidden; + border-radius: inherit; + pointer-events: none; + z-index: 0; +} +.hero__orb { + position: absolute; + border-radius: 50%; + filter: blur(46px); + opacity: 0; + transition: opacity 900ms var(--ease); +} +.hero__orb--a { + width: 340px; + height: 340px; + inset-block-start: -130px; + inset-inline-start: -80px; + background: radial-gradient(circle at 40% 40%, rgba(217, 147, 104, 0.55), rgba(217, 147, 104, 0) 68%); +} +.hero__orb--b { + width: 420px; + height: 420px; + inset-block-end: -190px; + inset-inline-end: -60px; + background: radial-gradient(circle at 50% 50%, rgba(196, 112, 60, 0.42), rgba(196, 112, 60, 0) 70%); +} +html.fx-motion .hero__orb { + opacity: 1; + animation: fx-orb-a 19s ease-in-out infinite alternate; +} +html.fx-motion .hero__orb--b { + animation: fx-orb-b 23s ease-in-out infinite alternate; +} + +/* เส้น светлоวิ่งผ่านปุ่มหลัก */ +.btn--primary { + position: relative; + overflow: hidden; +} +html.fx-motion .btn--primary::after { + content: ""; + position: absolute; + inset-block: -60%; + inset-inline-start: 0; + width: 42%; + background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.42), transparent); + transform: translate3d(-140%, 0, 0) rotate(12deg); + pointer-events: none; +} +html.fx-motion .btn--primary:hover::after, +html.fx-motion .btn--primary:focus-visible::after { + animation: fx-sheen 900ms var(--ease); +} + +/* ------------------------------------------------ reveal เมื่อเลื่อนถึง */ +html.fx-motion [data-reveal] { + opacity: 0; +} +html.fx-motion [data-reveal][data-revealed] { + animation: fx-rise-in 660ms cubic-bezier(0.16, 0.84, 0.28, 1) both; + animation-delay: var(--fx-delay, 0ms); +} +html.fx-motion [data-reveal="pop"][data-revealed] { + animation-name: fx-pop-in; +} +html.fx-motion [data-reveal="fade"][data-revealed] { + animation-name: fx-fade-in; +} +html.fx-motion [data-reveal="slide"][data-revealed] { + animation-name: fx-slide-in; +} + +/* การ์ดโปรเจค: ยกขึ้นเฉพาะตอน hover (ไม่ชนกับ keyframe ของ reveal) */ +html.fx-motion .project-card { + will-change: transform; +} +html.fx-motion .project-card[data-revealed] { + animation-fill-mode: both; +} + +/* หัวข้อ section: ขีดเส้นใต้วาดจากซ้าย */ +.section-head__title { + position: relative; + display: inline-block; + padding-bottom: 6px; +} +.section-head__title::after { + content: ""; + position: absolute; + inset-inline-start: 0; + inset-block-end: 0; + width: 100%; + height: 3px; + border-radius: 3px; + background: linear-gradient(90deg, var(--brand-500), var(--brand-200)); + transform: scaleX(0); + transform-origin: 0 50%; +} +html.fx-motion .section-head[data-revealed] .section-head__title::after { + animation: fx-line 760ms var(--ease) 240ms both; +} +@keyframes fx-line { + from { + transform: scaleX(0); + } + to { + transform: scaleX(1); + } +} + +/* ลูกเล่น hover: ไอคอนการ์ดเอียงขึ้นเล็กน้อย */ +@media (hover: hover) { + .project-card:hover .project-card__icon { + transform: rotate(-4deg) scale(1.04); + transition: transform 220ms var(--ease); + } + .project-card__icon { + transition: transform 220ms var(--ease); + } +} + +/* --------------------------------------------------- ทางออกสำหรับทุกกรณี */ +@media (prefers-reduced-motion: reduce) { + html.fx-motion [data-reveal], + html.fx-motion [data-reveal][data-revealed], + html.fx-motion .hero__eyebrow, + html.fx-motion .hero__lead, + html.fx-motion .hero__deco-card, + html.fx-motion .fx-word > span, + html.fx-motion .section-head[data-revealed] .section-head__title::after, + html.fx-motion .btn--primary::after { + animation: none !important; + opacity: 1 !important; + transform: none !important; + filter: none !important; + } + html.fx-motion .hero__orb { + animation: none !important; + } +} diff --git a/index.html b/index.html index 7675bd5..eced9af 100644 --- a/index.html +++ b/index.html @@ -2,6 +2,19 @@ + โปรเจคอดิเรกของเรา - + @@ -19,9 +32,11 @@ + +