feat(motion): scroll-reveal and cinematic entrance animations
- 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 <html>.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
This commit is contained in:
1 parent
c00bc62272
commit
2950295690
10 files changed
+503
-12
No files matched your search
@@ -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)
|
||||
@@ -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` และ `<meta name="app-version">` พร้อมกัน
|
||||
|
||||
## 9. Motion (ลูกเล่นภาพเคลื่อนไหว)
|
||||
|
||||
ไฟล์: `assets/css/motion.css` + `ui/motion.js`
|
||||
|
||||
**สัญญาความปลอดภัยของเนื้อหา** — ห้ามซ่อนเนื้อหาใน CSS หลัก:
|
||||
- inline script ใน `<head>` ใส่ `.fx-motion` ที่ `<html>` ก่อนวาดเฟรมแรก เว้นแต่ผู้ใช้ตั้ง `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 หยุด — อย่าด่วนสรุปว่าโค้ดพัง ให้ยกแท็บขึ้นหน้าก่อนวัด
|
||||
+2
-1
@@ -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;
|
||||
|
||||
@@ -0,0 +1,298 @@
|
||||
/* ==========================================================================
|
||||
motion.css — ลูกเล่นภาพเคลื่อนไหว
|
||||
สัญญา: ซ่อนเนื้อหาเฉพาะเมื่อ <html> มีคลาส .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;
|
||||
}
|
||||
}
|
||||
+16
-1
@@ -2,6 +2,19 @@
|
||||
<html lang="th">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<script>
|
||||
/* ใส่คลาส fx-motion ก่อนวาดเฟรมแรก เพื่อไม่ให้เนื้อหากะพริบ
|
||||
(JS ปิด หรือผู้ใช้ตั้ง reduced-motion → ไม่ใส่คลาส → เนื้อหาเห็นปกติทันที) */
|
||||
(function () {
|
||||
try {
|
||||
if (!window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
||||
document.documentElement.classList.add("fx-motion");
|
||||
}
|
||||
} catch (e) {
|
||||
/* ถ้า matchMedia ใช้ไม่ได้ ก็ไม่ต้องมีอนิเมชัน */
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
||||
<title>โปรเจคอดิเรกของเรา</title>
|
||||
<meta
|
||||
@@ -9,7 +22,7 @@
|
||||
content="รายชื่อโปรเจคอดิเรกของเรา เลือกโปรเจคที่อยากดูได้เลย ทุกเว็บใช้ SSL ฟรีต่ออายุอัตโนมัติ"
|
||||
/>
|
||||
<meta name="theme-color" content="#8A4722" />
|
||||
<meta name="app-version" content="2026.11.19.1" />
|
||||
<meta name="app-version" content="2026.11.19.2" />
|
||||
<link rel="manifest" href="manifest.json" />
|
||||
<link rel="icon" type="image/png" sizes="192x192" href="icons/icon-192.png" />
|
||||
<link rel="icon" type="image/png" sizes="64x64" href="icons/favicon-64.png" />
|
||||
@@ -19,9 +32,11 @@
|
||||
<link rel="stylesheet" href="assets/css/theme.css" />
|
||||
<link rel="stylesheet" href="assets/css/home.css" />
|
||||
<link rel="stylesheet" href="assets/css/admin.css" />
|
||||
<link rel="stylesheet" href="assets/css/motion.css" />
|
||||
<script type="module" src="ui/app.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="scroll-progress" aria-hidden="true"><span class="scroll-progress__bar"></span></div>
|
||||
<a class="skip-link" href="#main">ข้ามไปที่เนื้อหาหลัก</a>
|
||||
|
||||
<header class="site-header">
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
กติกา: bump VERSION เฉพาะเมื่อแก้ไฟล์นี้หรือรายการ PRECACHE
|
||||
เนื้อหา (HTML/CSS/JS/JSON) ใช้ network-first จึงไม่ต้อง bump */
|
||||
|
||||
const VERSION = "2026.11.19.1";
|
||||
const VERSION = "2026.11.19.2";
|
||||
const CACHE = `hobbypj-${VERSION}`;
|
||||
|
||||
const PRECACHE = [
|
||||
@@ -12,11 +12,13 @@ const PRECACHE = [
|
||||
"./assets/css/theme.css",
|
||||
"./assets/css/home.css",
|
||||
"./assets/css/admin.css",
|
||||
"./assets/css/motion.css",
|
||||
"./ui/app.js",
|
||||
"./ui/router.js",
|
||||
"./ui/ui.js",
|
||||
"./ui/data.js",
|
||||
"./ui/pwa.js",
|
||||
"./ui/motion.js",
|
||||
"./ui/views/home.js",
|
||||
"./ui/views/admin.js",
|
||||
"./data/projects.json",
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { hydrateIcons, toast } from "./ui.js";
|
||||
import { loadProjects, normalizeData } from "./data.js";
|
||||
import { defineRoutes, markActiveNav, onRouteChange, startRouter } from "./router.js";
|
||||
import { countUpInside, initMotion, initReveal } from "./motion.js";
|
||||
import { homeView } from "./views/home.js";
|
||||
import { adminView } from "./views/admin.js";
|
||||
import "./pwa.js";
|
||||
@@ -51,6 +52,8 @@ function renderRoute({ path, view }) {
|
||||
document.title = TITLES[path] || TITLES["/"];
|
||||
window.scrollTo({ top: 0, behavior: "auto" });
|
||||
main.focus({ preventScroll: true });
|
||||
initReveal(main);
|
||||
countUpInside(main);
|
||||
}
|
||||
|
||||
function updateChrome() {
|
||||
@@ -83,6 +86,7 @@ function skeleton() {
|
||||
|
||||
async function boot() {
|
||||
hydrateIcons();
|
||||
initMotion();
|
||||
skeleton();
|
||||
const result = await loadProjects();
|
||||
state.data = result.data;
|
||||
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
/* motion.js — reveal-on-scroll, แถบความคืบหน้า, นับเลขขึ้น
|
||||
หลักการ: ถ้า <html> ไม่มี .fx-motion (JS ปิด / reduced-motion) ให้ทุกอย่างเห็นทันที
|
||||
ห้ามซ่อนเนื้อหาใน CSS หลัก — ซ่อนเฉพาะใต้ .fx-motion */
|
||||
|
||||
const REDUCED = () => window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
||||
|
||||
export function motionEnabled() {
|
||||
return document.documentElement.classList.contains("fx-motion");
|
||||
}
|
||||
|
||||
/** เปิด/ปิดคลาส .fx-motion ตามการตั้งค่าผู้ใช้ (เรียกซ้ำได้เมื่อผู้ใช้เปลี่ยน setting) */
|
||||
export function syncMotionPreference() {
|
||||
document.documentElement.classList.toggle("fx-motion", !REDUCED());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- แถบเลื่อน */
|
||||
export function initScrollProgress() {
|
||||
const bar = document.querySelector(".scroll-progress__bar");
|
||||
if (!bar) return;
|
||||
let ticking = false;
|
||||
const update = () => {
|
||||
const doc = document.documentElement;
|
||||
const scrollable = doc.scrollHeight - window.innerHeight;
|
||||
const ratio = scrollable > 0 ? Math.min(1, Math.max(0, window.scrollY / scrollable)) : 0;
|
||||
bar.style.transform = `scaleX(${ratio.toFixed(4)})`;
|
||||
ticking = false;
|
||||
};
|
||||
window.addEventListener(
|
||||
"scroll",
|
||||
() => {
|
||||
if (ticking) return;
|
||||
ticking = true;
|
||||
requestAnimationFrame(update);
|
||||
},
|
||||
{ passive: true },
|
||||
);
|
||||
window.addEventListener("resize", update, { passive: true });
|
||||
update();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- reveal */
|
||||
export function initReveal(root = document) {
|
||||
const targets = [...root.querySelectorAll("[data-reveal]")];
|
||||
if (!targets.length) return;
|
||||
|
||||
// ไม่มี motion → เปิดให้เห็นทุกอันแล้วจบ
|
||||
if (!motionEnabled() || REDUCED()) {
|
||||
targets.forEach((el) => el.setAttribute("data-revealed", ""));
|
||||
return;
|
||||
}
|
||||
|
||||
const reveal = (el) => {
|
||||
if (el.hasAttribute("data-revealed")) return;
|
||||
// หน่วงแบบต่อเนื่องเฉพาะการ์ดในกริด (คิดตามคอลัมน์ ไม่ใช่ index สะสม)
|
||||
el.setAttribute("data-revealed", "");
|
||||
if (el.matches(".project-card")) countUpInside(el);
|
||||
};
|
||||
|
||||
if (!("IntersectionObserver" in window)) {
|
||||
targets.forEach(reveal);
|
||||
return;
|
||||
}
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) => {
|
||||
entries.forEach((entry) => {
|
||||
if (entry.isIntersecting) {
|
||||
reveal(entry.target);
|
||||
observer.unobserve(entry.target);
|
||||
return;
|
||||
}
|
||||
// กระโดดข้ามบล็อกไปแล้ว (anchor jump / คืนตำแหน่ง scroll) — ต้องเปิดให้เห็น ไม่ปล่อยค้างซ่อน
|
||||
const rootTop = entry.rootBounds ? entry.rootBounds.top : 0;
|
||||
if (entry.boundingClientRect.bottom <= rootTop) {
|
||||
reveal(entry.target);
|
||||
observer.unobserve(entry.target);
|
||||
}
|
||||
});
|
||||
},
|
||||
{ rootMargin: "2000px 0px -6% 0px", threshold: 0.01 },
|
||||
);
|
||||
|
||||
targets.forEach((el) => observer.observe(el));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- count up */
|
||||
export function countUpInside(scope = document) {
|
||||
if (!motionEnabled() || REDUCED()) return;
|
||||
scope.querySelectorAll("[data-countup]").forEach((el) => {
|
||||
if (el.dataset.countupDone === "1") return;
|
||||
el.dataset.countupDone = "1";
|
||||
const target = Number(el.getAttribute("data-countup")) || 0;
|
||||
if (target <= 0) return;
|
||||
const duration = 720;
|
||||
const start = performance.now();
|
||||
const tick = (now) => {
|
||||
const progress = Math.min(1, (now - start) / duration);
|
||||
const eased = 1 - Math.pow(1 - progress, 3);
|
||||
el.textContent = String(Math.round(target * eased));
|
||||
if (progress < 1) requestAnimationFrame(tick);
|
||||
else el.textContent = String(target);
|
||||
};
|
||||
el.textContent = "0";
|
||||
requestAnimationFrame(tick);
|
||||
});
|
||||
}
|
||||
|
||||
/** เรียกครั้งเดียวหลังโหลดหน้า */
|
||||
export function initMotion() {
|
||||
syncMotionPreference();
|
||||
initScrollProgress();
|
||||
if (typeof window.matchMedia === "function") {
|
||||
const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
|
||||
mq.addEventListener?.("change", () => {
|
||||
syncMotionPreference();
|
||||
if (!REDUCED()) initReveal(document);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/** แบ่งข้อความไทยเป็นช่วงคำ (ตัดด้วยช่องว่างเท่านั้น — ปลอดภัยกับสระ/วรรณยุกต์) */
|
||||
export function splitWordsHtml(text, escape, startDelay = 140, step = 85) {
|
||||
return String(text)
|
||||
.trim()
|
||||
.split(/\s+/)
|
||||
.map(
|
||||
(word, index) =>
|
||||
`<span class="fx-word" style="--fx-delay:${startDelay + index * step}ms"><span>${escape(
|
||||
word,
|
||||
)}</span></span>`,
|
||||
)
|
||||
.join("");
|
||||
}
|
||||
+6
-3
@@ -1,6 +1,7 @@
|
||||
/* views/admin.js — หลังบ้าน: แก้ชื่อ/คำอธิบาย/ลิงก์ แล้วเผยแพร่หรือดาวน์โหลด JSON */
|
||||
|
||||
import { escapeHtml, icon, isEmail, normalizeUrl, toast, debounce } from "../ui.js";
|
||||
import { initReveal } from "../motion.js";
|
||||
import {
|
||||
clearDraft,
|
||||
createProject,
|
||||
@@ -90,7 +91,7 @@ export function adminView(ctx) {
|
||||
<span data-status-extra></span>
|
||||
</div>
|
||||
|
||||
<section class="panel" aria-labelledby="site-panel-title">
|
||||
<section class="panel" data-reveal="fade" aria-labelledby="site-panel-title">
|
||||
<div class="panel__head">
|
||||
<h2 class="panel__title" id="site-panel-title">ข้อความบนหน้าเว็บ</h2>
|
||||
</div>
|
||||
@@ -120,7 +121,7 @@ export function adminView(ctx) {
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="panel" aria-labelledby="projects-panel-title">
|
||||
<section class="panel" data-reveal="fade" aria-labelledby="projects-panel-title">
|
||||
<div class="panel__head">
|
||||
<h2 class="panel__title" id="projects-panel-title">
|
||||
รายชื่อโปรเจค (<span data-project-count>${draft.projects.length}</span>)
|
||||
@@ -134,7 +135,7 @@ export function adminView(ctx) {
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="panel" aria-labelledby="publish-panel-title">
|
||||
<section class="panel" data-reveal="fade" aria-labelledby="publish-panel-title">
|
||||
<div class="panel__head">
|
||||
<h2 class="panel__title" id="publish-panel-title">ช่องทางบันทึก</h2>
|
||||
</div>
|
||||
@@ -184,6 +185,8 @@ export function adminView(ctx) {
|
||||
}
|
||||
refreshDirty();
|
||||
checkApi();
|
||||
// เรียกซ้ำได้เสมอ เพราะ mount() ถูกเรียกใหม่หลังกด “ทิ้งการแก้ไข”
|
||||
initReveal(root);
|
||||
}
|
||||
|
||||
function bindSiteFields() {
|
||||
|
||||
+14
-6
@@ -1,6 +1,7 @@
|
||||
/* views/home.js — หน้าแรก: ข้อความต้อนรับ + ค้นหา + การ์ดโปรเจค */
|
||||
|
||||
import { escapeHtml, hostOf, icon, normalizeUrl } from "../ui.js";
|
||||
import { initReveal, splitWordsHtml } from "../motion.js";
|
||||
|
||||
export function homeView(ctx) {
|
||||
let root = null;
|
||||
@@ -21,7 +22,7 @@ export function homeView(ctx) {
|
||||
});
|
||||
}
|
||||
|
||||
function cardHtml(project) {
|
||||
function cardHtml(project, index = 0) {
|
||||
const url = normalizeUrl(project.project_url);
|
||||
const host = hostOf(project.project_url);
|
||||
const name = escapeHtml(project.project_name || "ไม่มีชื่อโปรเจค");
|
||||
@@ -30,7 +31,7 @@ export function homeView(ctx) {
|
||||
? `<a href="${escapeHtml(url)}" target="_blank" rel="noopener noreferrer">${name}</a>`
|
||||
: `<span>${name}</span>`;
|
||||
return `
|
||||
<article class="project-card">
|
||||
<article class="project-card" data-reveal="pop" style="--fx-delay:${(index % 3) * 95}ms">
|
||||
<div class="project-card__top">
|
||||
<span class="project-card__icon" aria-hidden="true">${icon(project.icon)}</span>
|
||||
<div class="project-card__heading">
|
||||
@@ -70,7 +71,9 @@ export function homeView(ctx) {
|
||||
return;
|
||||
}
|
||||
gridEl.className = "project-grid";
|
||||
gridEl.innerHTML = items.map(cardHtml).join("");
|
||||
gridEl.innerHTML = items.map((project, index) => cardHtml(project, index)).join("");
|
||||
// การ์ดชุดใหม่หลังกรองต้องถูก observe/เปิดให้เห็นด้วย ไม่งั้นจะค้างที่ opacity 0
|
||||
initReveal(gridEl);
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -83,12 +86,17 @@ export function homeView(ctx) {
|
||||
root.innerHTML = `
|
||||
<div class="wrap">
|
||||
<section class="hero" aria-labelledby="hero-title">
|
||||
<div class="hero__ambience" aria-hidden="true">
|
||||
<span class="hero__orb hero__orb--a"></span>
|
||||
<span class="hero__orb hero__orb--b"></span>
|
||||
</div>
|
||||
<div class="hero__inner">
|
||||
<p class="hero__eyebrow">${icon("spark")}<span>${escapeHtml(
|
||||
site.site_title,
|
||||
)}</span></p>
|
||||
<h1 class="hero__title" id="hero-title">${escapeHtml(
|
||||
<h1 class="hero__title" id="hero-title">${splitWordsHtml(
|
||||
site.welcome_message,
|
||||
escapeHtml,
|
||||
)}</h1>
|
||||
<p class="hero__lead">รวมเว็บที่ทำเองไว้ในที่เดียว เลือกดูได้ตามใจ ไม่มีโฆษณา ไม่มีล็อกอิน</p>
|
||||
<form class="searchbar" role="search" autocomplete="off">
|
||||
@@ -101,7 +109,7 @@ export function homeView(ctx) {
|
||||
</button>
|
||||
</form>
|
||||
<div class="hero__meta">
|
||||
<span>${icon("folder")}${total} โปรเจค</span>
|
||||
<span>${icon("folder")}<span data-countup="${total}">${total}</span> โปรเจค</span>
|
||||
<span>${icon("shield")}${escapeHtml(site.ssl_note)}</span>
|
||||
${
|
||||
withEmail
|
||||
@@ -124,7 +132,7 @@ export function homeView(ctx) {
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="section-head">
|
||||
<div class="section-head" data-reveal="fade">
|
||||
<div>
|
||||
<h2 class="section-head__title" id="projects-title">รายชื่อโปรเจค</h2>
|
||||
<p class="section-head__sub">กดที่การ์ดเพื่อเปิดเว็บนั้นในแท็บใหม่</p>
|
||||
|
||||
Reference in new issue
Block a user