Skip to content

Commit 5ddf301

Browse files
committed
feat: enhance ChronologyOfStellarTrails with localStorage integration for task navigation and improve button interactions
1 parent 8a25764 commit 5ddf301

4 files changed

Lines changed: 143 additions & 9 deletions

File tree

pages/TwelveOrderStars.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ <h4 class="detail">发射地点:酒泉卫星发射基地</h4>
123123
</div>
124124
</div>
125125
<div class="video-player" id="video-player">
126-
<video id="launch-video">
126+
<video id="launch-video" autoplay loop controls>
127127
<source src="../assets/videos/launch.mp4" type="video/mp4">
128128
您的浏览器不支持视频播放
129129
</video>

scripts/ChronologyOfStellarTrails/detail.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,12 +547,60 @@ function handleNavigation() {
547547
});
548548
}
549549

550+
/**
551+
* 根据localStorage中的ID初始化当前任务索引
552+
*/
553+
function initCurrentMissionIndex() {
554+
const selectedCardId = localStorage.getItem('selectedCardId');
555+
556+
if (selectedCardId) {
557+
// 根据ID查找对应的任务索引
558+
const missionIndex = missionData.findIndex(mission => mission.id == selectedCardId);
559+
560+
if (missionIndex !== -1) {
561+
currentMissionIndex = missionIndex;
562+
} else {
563+
// 如果找不到对应的ID,默认显示第一个
564+
currentMissionIndex = 0;
565+
}
566+
567+
// 清除localStorage中的数据,避免下次进入时还是这个ID
568+
localStorage.removeItem('selectedCardId');
569+
} else {
570+
// 如果没有存储的ID,默认显示第一个
571+
currentMissionIndex = 0;
572+
}
573+
}
574+
575+
/**
576+
* 处理返回按钮点击
577+
*/
578+
function handleBackButton() {
579+
const backButton = document.querySelector('.arrow');
580+
if (backButton) {
581+
backButton.addEventListener('click', (e) => {
582+
e.preventDefault();
583+
584+
// 保存当前任务的ID到localStorage,用于返回时滚动定位
585+
const currentMission = missionData[currentMissionIndex];
586+
if (currentMission) {
587+
localStorage.setItem('scrollToCardId', currentMission.id);
588+
}
589+
590+
// 跳转回列表页
591+
window.location.href = 'ChronologyOfStellarTrails.html';
592+
});
593+
}
594+
}
595+
550596
// 初始化页面
551597
document.addEventListener("DOMContentLoaded", function () {
598+
initCurrentMissionIndex(); // 根据localStorage初始化任务索引
552599
StartBackground(); // 初始化星空背景和流星效果
553600
initOrbitAnimation(); // 初始化轨道动画
554-
updateMissionContent(currentMissionIndex, 'initial'); // 初始加载第一条任务数据
601+
updateMissionContent(currentMissionIndex, 'initial'); // 初始加载对应的任务数据
555602
handleNavigation(); // 设置导航按钮的点击事件监听
603+
handleBackButton(); // 设置返回按钮的点击事件监听
556604
// 初始化鼠标控制器
557605
new Mouse({
558606
defaultCursor: '../assets/images/common/MouseDefault.svg',

scripts/ChronologyOfStellarTrails/index.js

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,16 @@ function renderCards(container, cardsData) {
129129

130130
let btn = '';
131131
if (index % 2 === 0) {
132-
btn = `<a href="ChronologyOfStellarTrailsDetails.html" class="detail-btn">
132+
btn = `<button class="detail-btn" data-id="${card.id}">
133133
查看详情
134134
<svg xmlns="http://www.w3.org/2000/svg" style="margin-left: 2rem;" width="128" height="128" viewBox="0 0 24 24"><path fill="#ffffff" d="M16.175 13H4v-2h12.175l-5.6-5.6L12 4l8 8l-8 8l-1.425-1.4z"/></svg>
135-
</a>`
135+
</button>`
136136

137137
} else {
138-
btn = `<a href="ChronologyOfStellarTrailsDetails.html" class="detail-btn">
138+
btn = `<button class="detail-btn" data-id="${card.id}">
139139
<svg xmlns="http://www.w3.org/2000/svg" style="margin-right: 2rem;" width="128" height="128" viewBox="0 0 24 24"><path fill="#ffffff" d="M16.175 13H4v-2h12.175l-5.6-5.6L12 4l8 8l-8 8l-1.425-1.4z"/></svg>
140140
查看详情
141-
</a>`
141+
</button>`
142142
}
143143

144144

@@ -161,6 +161,29 @@ function renderCards(container, cardsData) {
161161

162162
container.appendChild(cardElement);
163163
});
164+
165+
// 添加详情按钮点击事件监听
166+
addDetailButtonListeners();
167+
}
168+
169+
/**
170+
* 为详情按钮添加点击事件监听
171+
*/
172+
function addDetailButtonListeners() {
173+
const detailButtons = document.querySelectorAll('.detail-btn');
174+
175+
detailButtons.forEach(button => {
176+
button.addEventListener('click', (e) => {
177+
e.preventDefault();
178+
const cardId = button.getAttribute('data-id');
179+
180+
// 将选中的卡片ID存储到localStorage
181+
localStorage.setItem('selectedCardId', cardId);
182+
183+
// 跳转到详情页
184+
window.location.href = 'ChronologyOfStellarTrailsDetails.html';
185+
});
186+
});
164187
}
165188

166189
/**
@@ -202,6 +225,41 @@ function observeTitles() {
202225
});
203226
}
204227

228+
/**
229+
* 滚动到指定ID的卡片
230+
*/
231+
function scrollToCard() {
232+
const scrollToCardId = localStorage.getItem('scrollToCardId');
233+
234+
if (scrollToCardId) {
235+
// 清除localStorage中的数据
236+
localStorage.removeItem('scrollToCardId');
237+
238+
// 等待页面渲染完成后再滚动
239+
setTimeout(() => {
240+
const targetCard = document.querySelector(`[data-id="${scrollToCardId}"]`);
241+
242+
if (targetCard) {
243+
// 滚动到目标卡片,并居中显示
244+
targetCard.scrollIntoView({
245+
behavior: 'smooth',
246+
block: 'center',
247+
inline: 'nearest'
248+
});
249+
250+
// 添加高亮效果
251+
targetCard.style.transition = 'all 0.5s ease';
252+
targetCard.style.transform = 'scale(1.02)';
253+
254+
// 3秒后移除高亮效果
255+
setTimeout(() => {
256+
targetCard.style.transform = '';
257+
}, 2000);
258+
}
259+
}, 200); // 等待500ms确保页面渲染完成
260+
}
261+
}
262+
205263
document.addEventListener("DOMContentLoaded", () => {
206264
const header = document.querySelector('.header');
207265
const starContainer = document.querySelector('.star-bg');
@@ -239,6 +297,9 @@ document.addEventListener("DOMContentLoaded", () => {
239297
// 监听标题可见性
240298
observeTitles();
241299

300+
// 检查是否需要滚动到特定卡片
301+
scrollToCard();
302+
242303
// 初始化鼠标控制器
243304
new Mouse({
244305
defaultCursor: '../assets/images/common/MouseDefault.svg',

styles/ChronologyOfStellarTrails/index.css

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ body {
6767
padding: 2rem 0;
6868
display: flex;
6969
flex-direction: column;
70+
overflow: visible;
7071
}
7172

7273
/* 中轴线 */
@@ -86,9 +87,11 @@ body {
8687
.card {
8788
position: relative;
8889
width: 100%;
89-
height: 64.7rem;
90+
min-height: 64.7rem;
9091
opacity: 0;
9192
transition: opacity 0.8s ease, transform 0.8s ease;
93+
z-index: 10;
94+
overflow: visible;
9295
}
9396

9497
.card.visible {
@@ -98,12 +101,14 @@ body {
98101

99102
.card .left {
100103
width: 65.067rem;
104+
position: relative;
101105
}
102106

103107
/* 奇数卡片在左侧 */
104108
.card:nth-child(odd) .left {
105109
align-self: flex-start;
106110
margin-right: auto;
111+
z-index: 100;
107112
}
108113

109114
/* 偶数卡片在右侧 */
@@ -128,6 +133,8 @@ body {
128133
color: white;
129134
display: flex;
130135
flex-direction: column;
136+
position: relative;
137+
overflow: visible;
131138
}
132139

133140
.card .left .card-year {
@@ -163,16 +170,33 @@ body {
163170
font-size: 2.4rem;
164171
font-family: fys, sans-serif;
165172
color: rgba(255, 255, 255, 1);
173+
position: relative;
166174
z-index: 1000;
175+
border: none;
176+
cursor: pointer;
177+
transition: all 0.3s ease;
178+
background-color: transparent;
179+
flex-shrink: 0;
180+
box-sizing: border-box;
181+
}
182+
183+
.card .left .detail-btn:hover {
184+
transform: scale(1.05);
185+
filter: brightness(1.1);
167186
}
168187

169188
.card:nth-child(odd) .detail-btn {
170189
align-self: flex-end;
171-
z-index: 1000;
190+
z-index: 999999;
191+
margin-right: 0;
192+
position: relative;
172193
}
173194

174195
.card:nth-child(even) .detail-btn {
175196
align-self: flex-start;
197+
z-index: 1000;
198+
margin-left: 0;
199+
position: relative;
176200
}
177201

178202
.card .left .detail-btn svg {
@@ -224,7 +248,8 @@ body {
224248
transform: translateY(-50%);
225249
transition: opacity 0.5s ease, transform 0.5s ease;
226250
white-space: nowrap;
227-
z-index: 2;
251+
z-index: 1;
252+
pointer-events: none;
228253
}
229254

230255
.card:nth-child(odd) .card-title {

0 commit comments

Comments
 (0)