-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeatureDisplayPage.astro
More file actions
426 lines (377 loc) · 10.6 KB
/
FeatureDisplayPage.astro
File metadata and controls
426 lines (377 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
---
import "@styles/harmonyos-sans.css";
interface Props {
title: string;
direction?: "left" | "right";
}
const { title, direction = "left" } = Astro.props;
---
<div class={`feature-section ${direction}`} data-feature-section>
<div class="scroll-container" data-scroll-height>
<div class="sticky-viewport">
<div class="center-header">
<h2 class="title-text">{title}</h2>
</div>
<div class="main-layout">
<div class="image-stage-container">
<div class="image-stage">
<div class="image-stack" data-image-presenter></div>
</div>
</div>
<div class="ring-system-wrapper">
<div class="ring-visual">
<div class="particle-ring"></div>
<div class="particle-dots"></div>
</div>
<div class="labels-track" data-labels-container>
<slot />
</div>
</div>
</div>
</div>
</div>
</div>
<style>
:root {
--feature-content-padding: clamp(24px, 4vw, 56px);
}
.feature-section {
position: relative;
width: 100%;
}
/* 核心:scroll-container 必须有明确的物理高度,sticky 才会生效 */
.scroll-container {
position: relative;
height: 400vh;
}
.sticky-viewport {
position: sticky;
top: var(--navbar-height);
width: 100%;
height: calc(100vh - var(--navbar-height));
overflow: hidden; /* 必须 hidden,防止内部圆环溢出导致 Sticky 失效 */
}
.center-header {
position: absolute;
top: 2rem;
width: 100%;
display: flex;
justify-content: center;
z-index: 100;
}
.title-text {
font-family:
"Satoshi-Bold",
"HarmonyOS-Sans-SC-Bold",
"PingFang SC",
"Microsoft YaHei",
sans-serif;
font-size: clamp(2rem, 5vw, 3.5rem);
font-weight: 600;
color: var(--text-color);
text-transform: uppercase;
margin: 0;
}
.main-layout {
display: grid;
grid-template-columns: 1fr 1fr;
width: 100%;
height: 100vh;
padding: 9rem var(--feature-content-padding) 0;
box-sizing: border-box;
}
@media (max-width: 768px) {
.main-layout {
grid-template-columns: 1fr;
grid-template-rows: auto auto;
padding-top: 5.5rem;
}
.left .image-stage-container,
.right .image-stage-container {
order: 1;
}
.left .ring-system-wrapper,
.right .ring-system-wrapper {
order: 2;
}
}
@media (min-width: 768px) {
.left .image-stage-container {
order: 1;
}
.left .ring-system-wrapper {
order: 2;
}
.right .image-stage-container {
order: 2;
}
.right .ring-system-wrapper {
order: 1;
}
}
.ring-system-wrapper {
position: relative;
display: flex;
align-items: center;
justify-content: center;
}
.ring-visual {
position: absolute;
width: 80vh;
height: 80vh;
pointer-events: none;
z-index: -1;
}
.left .ring-visual {
right: -10vh;
}
.right .ring-visual {
left: -10vh;
}
.particle-ring {
position: absolute;
inset: 0;
border: 1px solid var(--accent-color);
border-radius: 50%;
/* opacity: 0.5; */
mask-image: radial-gradient(circle, transparent 45%, black 100%);
}
.particle-dots {
position: absolute;
inset: -20px;
background-image: radial-gradient(
circle,
var(--accent-color) 1.5px,
transparent 1.5px
);
background-size: 40px 40px;
opacity: 0.2;
border-radius: 50%;
animation: rotateRing 150s linear infinite;
}
@keyframes rotateRing {
from {
transform: rotate(0);
}
to {
transform: rotate(360deg);
}
}
.labels-track {
position: absolute;
inset: 0;
}
:global(.present-img-wrapper) {
position: absolute;
inset: 0;
opacity: 0;
transform: scale(1.06);
filter: blur(18px);
transition:
opacity 0.7s ease,
transform 0.8s cubic-bezier(0.22, 1, 0.36, 1),
filter 0.8s ease;
}
:global(.present-img-wrapper.active) {
opacity: 1;
transform: scale(1);
filter: blur(0);
}
:global(.present-img-wrapper img) {
width: 100%;
height: 100%;
object-fit: cover;
mask-image: linear-gradient(
to bottom,
transparent 0%,
black 10%,
black 90%,
transparent 100%
);
}
.main-layout {
display: grid;
/* 宽屏比例:图片 60vw,剩下给词条系统 */
/* grid-template-columns: 60vw 1fr; */
width: 100%;
height: 100%;
align-items: center;
}
@media (min-width: 768px) {
.left .main-layout {
grid-template-columns: minmax(0, 55vw) minmax(280px, 1fr);
}
.right .main-layout {
grid-template-columns: minmax(280px, 1fr) minmax(0, 55vw);
}
}
.image-stage-container {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
}
.image-stage {
position: relative;
width: min(100%, 840px);
aspect-ratio: 16 / 10;
background-color: var(--bg-color-dimmer);
border-radius: clamp(20px, 3vw, 40px);
overflow: hidden;
border: 1px solid var(--border-color);
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}
@media (min-width: 768px) {
.image-stage-container {
transform: translate3d(0, -32px, 0);
}
}
/* 词条基础样式确保居中 */
:global(.feature-label-display) {
position: absolute;
left: 50%;
top: -6em;
will-change: transform, opacity;
transition:
transform 0.42s cubic-bezier(0.22, 1, 0.36, 1),
opacity 0.28s ease,
filter 0.42s ease;
}
.left :global(.feature-copy) {
text-align: right;
align-items: flex-end;
}
.right :global(.feature-copy) {
text-align: left;
align-items: flex-start;
}
@media (max-width: 768px) {
:global(.feature-label-display) {
top: -5.25em;
}
.left :global(.feature-copy),
.right :global(.feature-copy) {
text-align: center;
align-items: center;
}
.left .ring-system-wrapper,
.right .ring-system-wrapper {
padding-left: 0;
padding-right: 0;
}
}
</style>
<script>
function setupCircularPPT() {
const sections = document.querySelectorAll("[data-feature-section]");
const scrollUnitsPerItem = 72;
sections.forEach((section) => {
const holder = section.querySelector(
"[data-scroll-height]",
) as HTMLElement;
const labelsContainer = section.querySelector("[data-labels-container]");
const presenter = section.querySelector("[data-image-presenter]");
if (!holder || !labelsContainer || !presenter) return;
const sourceItems = labelsContainer.querySelectorAll(
".feature-source-item",
);
const count = sourceItems.length;
let visualIndex = 0;
let targetIndex = 0;
// --- 体检环节 ---
console.log(`[Feature] 初始化: 词条数 ${count}`);
holder.style.height = `${Math.max(count * scrollUnitsPerItem, 220)}vh`; // 缩短每段滚动距离,保留 sticky 手感
if (presenter.children.length === 0) {
sourceItems.forEach((item) => {
const img = item.querySelector("img, picture");
if (img) {
const w = document.createElement("div");
w.className = "present-img-wrapper";
w.appendChild(img.cloneNode(true));
presenter.appendChild(w);
}
});
}
const displayLabels = labelsContainer.querySelectorAll(
".feature-label-display",
);
const imageWrappers = presenter.querySelectorAll(".present-img-wrapper");
// 核心计算逻辑
const update = () => {
const rect = section.getBoundingClientRect();
const navbarHeight =
parseFloat(
getComputedStyle(document.documentElement).getPropertyValue(
"--navbar-height",
),
) || 0;
const vh = window.innerHeight - navbarHeight;
const isMobile = window.innerWidth <= 768;
// 【物理诊断】:计算当前滚动进度
// 当 section 抵达导航栏下沿时开始计入进度
const relativeScroll = navbarHeight - rect.top;
const maxScroll = Math.max(holder.offsetHeight - vh, 1);
// 进度锁定在 0-1 之间
const progress = Math.max(
0,
Math.min(0.999, relativeScroll / (maxScroll || 1)),
);
targetIndex = Math.round(progress * (count - 1));
visualIndex += (targetIndex - visualIndex) * 0.16;
if (Math.abs(targetIndex - visualIndex) < 0.002) {
visualIndex = targetIndex;
}
const activeIdx = targetIndex;
// 圆弧数学模型
const radius = vh * 0.45;
const angleStep = Math.PI / 3.5;
const isLeft = section.classList.contains("left");
const anchorX = isMobile ? "-50%" : isLeft ? "-10%" : "-90%";
const biasX = isMobile ? 0 : isLeft ? -12 : 12;
displayLabels.forEach((label, i) => {
const el = label as HTMLElement;
const offset = visualIndex - i;
const angle = -offset * angleStep; // 负号确保滚动方向正确
const xDir = isLeft ? -1 : 1;
const tx = xDir * radius * (Math.cos(angle) - 1);
const ty = radius * Math.sin(angle);
const dist = Math.abs(offset);
const opacity = Math.max(0, 1 - dist * 1.5);
const scale = Math.max(0.5, 1.2 - dist * 0.4);
// 使用最稳健的 transform 组合
el.style.transform = `translate(${anchorX}, -50%) translate(${tx + biasX}px, ${ty}px) scale(${scale})`;
el.style.opacity = opacity.toString();
el.style.filter = `blur(${dist * 6}px)`;
el.classList.toggle("active", i === activeIdx);
});
imageWrappers.forEach((img, i) =>
img.classList.toggle("active", i === activeIdx),
);
};
// --- 关键:使用逐帧引擎替代事件监听 ---
let isTracking = false;
const loop = () => {
if (!isTracking) return;
update();
requestAnimationFrame(loop);
};
// 只要 section 在视口内(即便只是边缘),就强制开启高频检查
const observer = new IntersectionObserver(
(entries) => {
if (entries[0].isIntersecting) {
isTracking = true;
console.log("[Feature] 激活跟踪");
loop();
} else {
isTracking = false;
console.log("[Feature] 停止跟踪");
}
},
{ threshold: 0, rootMargin: "100px" },
);
observer.observe(section);
});
}
setupCircularPPT();
document.addEventListener("astro:after-swap", setupCircularPPT);
</script>