Skip to content

Commit 3502c05

Browse files
committed
refactor: 改善學習場景卡片的顯示方式
- 移除透明遮罩效果,使用純白背景提升可讀性 - 電腦版改為網格布局,避免橫向滾動的操作困難 - 手機版保留橫向滾動設計,維持觸控體驗 - 滾動指示器僅在手機版顯示
1 parent 7a22a9e commit 3502c05

2 files changed

Lines changed: 97 additions & 104 deletions

File tree

script.js

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,18 +291,75 @@ window.onload = function() {
291291
initScenarioScroll();
292292
}
293293

294+
// 場景導航功能
295+
function scrollScenarios(direction) {
296+
const scenarioList = document.querySelector('.scenario-list');
297+
const scenarioItems = document.querySelectorAll('.scenario-item');
298+
299+
if (!scenarioList || !scenarioItems.length) return;
300+
301+
// 計算每個項目的寬度和間距
302+
const itemWidth = scenarioItems[0].offsetWidth + 20; // 包含 gap
303+
const currentScroll = scenarioList.scrollLeft;
304+
const maxScroll = scenarioList.scrollWidth - scenarioList.clientWidth;
305+
306+
let targetScroll;
307+
308+
if (direction === 'prev') {
309+
targetScroll = Math.max(0, currentScroll - itemWidth);
310+
} else {
311+
targetScroll = Math.min(maxScroll, currentScroll + itemWidth);
312+
}
313+
314+
scenarioList.scrollTo({
315+
left: targetScroll,
316+
behavior: 'smooth'
317+
});
318+
319+
// 更新按鈕狀態
320+
setTimeout(updateNavButtons, 300);
321+
}
322+
323+
// 更新導航按鈕狀態
324+
function updateNavButtons() {
325+
const scenarioList = document.querySelector('.scenario-list');
326+
const prevBtn = document.querySelector('.scenario-nav-btn.prev');
327+
const nextBtn = document.querySelector('.scenario-nav-btn.next');
328+
329+
if (!scenarioList || !prevBtn || !nextBtn) return;
330+
331+
const scrollLeft = scenarioList.scrollLeft;
332+
const maxScroll = scenarioList.scrollWidth - scenarioList.clientWidth;
333+
334+
// 更新上一個按鈕
335+
if (scrollLeft <= 10) {
336+
prevBtn.classList.add('disabled');
337+
} else {
338+
prevBtn.classList.remove('disabled');
339+
}
340+
341+
// 更新下一個按鈕
342+
if (scrollLeft >= maxScroll - 10) {
343+
nextBtn.classList.add('disabled');
344+
} else {
345+
nextBtn.classList.remove('disabled');
346+
}
347+
}
348+
294349
// 場景滾動功能
295350
function initScenarioScroll() {
296351
const scenarioList = document.querySelector('.scenario-list');
297352
const scrollDots = document.querySelectorAll('.scroll-dot');
298353
const scenarioItems = document.querySelectorAll('.scenario-item');
299354
const scenarioWrapper = document.querySelector('.scenario-wrapper');
355+
const scenariosSection = document.querySelector('.scenarios');
300356

301357
if (!scenarioList || !scrollDots.length || !scenarioItems.length) return;
302358

303359
// 計算每個項目的寬度和間距
304360
const itemWidth = scenarioItems[0].offsetWidth + 20; // 包含 gap
305361

362+
306363
// 更新滾動指示器
307364
function updateScrollIndicator() {
308365
const scrollLeft = scenarioList.scrollLeft;
@@ -339,7 +396,10 @@ function initScenarioScroll() {
339396
let scrollTimeout;
340397
scenarioList.addEventListener('scroll', () => {
341398
clearTimeout(scrollTimeout);
342-
scrollTimeout = setTimeout(updateScrollIndicator, 50);
399+
scrollTimeout = setTimeout(() => {
400+
updateScrollIndicator();
401+
updateNavButtons();
402+
}, 50);
343403
});
344404

345405
// 點擊指示器滾動到對應場景
@@ -355,6 +415,7 @@ function initScenarioScroll() {
355415

356416
// 初始化指示器狀態
357417
updateScrollIndicator();
418+
updateNavButtons();
358419

359420
// 添加觸摸滑動支持
360421
let startX = 0;

style.css

Lines changed: 35 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -171,48 +171,39 @@ body {
171171
}
172172

173173
.scenario-list {
174-
display: flex;
175-
gap: 20px;
176-
overflow-x: auto;
177-
overflow-y: hidden;
178-
scroll-snap-type: x mandatory;
179-
scroll-behavior: smooth;
180-
-webkit-overflow-scrolling: touch;
174+
display: grid;
175+
grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
176+
gap: 24px;
181177
padding: 20px 0;
182178
margin: 0;
183-
cursor: grab;
184-
/* Safari 優化 */
185-
-webkit-transform: translateZ(0);
186-
-webkit-backface-visibility: hidden;
187179
}
188180

189181
@media (max-width: 768px) {
190182
.scenario-list {
183+
display: flex;
191184
gap: 15px;
185+
overflow-x: auto;
186+
overflow-y: hidden;
187+
scroll-snap-type: x mandatory;
188+
scroll-behavior: smooth;
189+
-webkit-overflow-scrolling: touch;
192190
padding: 20px 0;
191+
cursor: grab;
192+
/* Safari 優化 */
193+
-webkit-transform: translateZ(0);
194+
-webkit-backface-visibility: hidden;
195+
grid-template-columns: none;
193196
}
194197
}
195198

196-
.scenario-list::-webkit-scrollbar {
197-
height: 0;
198-
}
199-
200-
@media (min-width: 769px) {
201-
.scenario-list {
202-
padding: 20px calc(max((100vw - 1200px) / 2, 20px));
203-
margin: -20px calc(min((100vw - 1200px) / -2, -20px));
199+
@media (max-width: 768px) {
200+
.scenario-list::-webkit-scrollbar {
201+
height: 0;
204202
}
205203
}
206204

207-
/* 確保第一個和最後一個項目有足夠的空間 */
208-
.scenario-item:first-child {
209-
margin-left: 20px;
210-
}
211-
212-
.scenario-item:last-child {
213-
margin-right: 20px;
214-
}
215205

206+
/* 只在手機版添加邊距 */
216207
@media (max-width: 768px) {
217208
.scenario-item:first-child {
218209
margin-left: 20px;
@@ -223,38 +214,25 @@ body {
223214
}
224215
}
225216

226-
@media (min-width: 769px) {
227-
.scenario-item:first-child {
228-
margin-left: 0;
229-
}
230-
231-
.scenario-item:last-child {
232-
margin-right: 0;
233-
}
234-
}
235-
236217
.scenario-item {
237-
background: rgba(255, 255, 255, 0.72);
218+
background: #ffffff;
238219
color: #1d1d1f;
239220
padding: 40px;
240-
border: 1px solid rgba(255, 255, 255, 0.18);
221+
border: 1px solid #e5e5e7;
241222
border-radius: 18px;
242223
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
243224
position: relative;
244225
overflow: hidden;
245226
box-shadow: 0 4px 20px rgba(0,0,0,0.08);
246-
flex: 0 0 340px;
247-
scroll-snap-align: start;
248227
min-height: 420px;
249228
display: flex;
250229
flex-direction: column;
251-
backdrop-filter: blur(40px) saturate(1.8);
252-
-webkit-backdrop-filter: blur(40px) saturate(1.8);
253230
}
254231

255232
@media (max-width: 768px) {
256233
.scenario-item {
257234
flex: 0 0 calc(100vw - 80px);
235+
scroll-snap-align: start;
258236
padding: 20px;
259237
min-height: 400px;
260238
max-width: none;
@@ -277,7 +255,7 @@ body {
277255
.scenario-item:hover {
278256
transform: translateY(-10px) scale(1.02);
279257
box-shadow: 0 20px 60px rgba(0,0,0,0.15);
280-
background: rgba(255, 255, 255, 0.9);
258+
background: #ffffff;
281259
}
282260

283261
.scenario-item:hover::before {
@@ -512,13 +490,19 @@ body {
512490
font-size: 0.9rem;
513491
}
514492

515-
/* 滾動指示器 */
493+
/* 滾動指示器 - 只在手機版顯示 */
516494
.scroll-indicator {
517-
display: flex;
518-
justify-content: center;
519-
gap: 8px;
520-
margin-top: 32px;
521-
padding: 20px;
495+
display: none;
496+
}
497+
498+
@media (max-width: 768px) {
499+
.scroll-indicator {
500+
display: flex;
501+
justify-content: center;
502+
gap: 8px;
503+
margin-top: 32px;
504+
padding: 20px;
505+
}
522506
}
523507

524508
.scroll-dot {
@@ -536,59 +520,7 @@ body {
536520
box-shadow: 0 2px 8px rgba(0,0,0,0.2);
537521
}
538522

539-
/* 添加滑動提示漸變 */
540-
.scenario-wrapper::after {
541-
content: '';
542-
position: absolute;
543-
top: 20px;
544-
right: 0;
545-
bottom: 20px;
546-
width: 80px;
547-
background: linear-gradient(to left,
548-
rgba(251,251,253,0.95) 0%,
549-
rgba(251,251,253,0.8) 20%,
550-
rgba(251,251,253,0.4) 60%,
551-
rgba(251,251,253,0) 100%
552-
);
553-
pointer-events: none;
554-
z-index: 1;
555-
opacity: 1;
556-
transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
557-
}
558-
559-
.scenario-wrapper::before {
560-
content: '';
561-
position: absolute;
562-
top: 20px;
563-
left: 0;
564-
bottom: 20px;
565-
width: 80px;
566-
background: linear-gradient(to right,
567-
rgba(251,251,253,0.95) 0%,
568-
rgba(251,251,253,0.8) 20%,
569-
rgba(251,251,253,0.4) 60%,
570-
rgba(251,251,253,0) 100%
571-
);
572-
pointer-events: none;
573-
z-index: 1;
574-
opacity: 0;
575-
transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
576-
}
577-
578-
@media (min-width: 769px) {
579-
.scenario-wrapper::after,
580-
.scenario-wrapper::before {
581-
width: 100px;
582-
}
583-
}
584-
585-
.scenario-wrapper.scrolled::before {
586-
opacity: 1;
587-
}
588-
589-
.scenario-wrapper.scrolled-end::after {
590-
opacity: 0;
591-
}
523+
/* 移除滑動提示漸變效果 */
592524

593525
/* 場景卡片內容細節樣式 */
594526
.scenario-details {

0 commit comments

Comments
 (0)