-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
303 lines (261 loc) · 10.2 KB
/
script.js
File metadata and controls
303 lines (261 loc) · 10.2 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
// 目前没有交互功能,可以在这里添加
// 添加平滑滚动效果
document.querySelectorAll('nav a').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
// 移除所有active类
document.querySelectorAll('nav a').forEach(a => a.classList.remove('active'));
// 添加active类到当前点击的链接
this.classList.add('active');
// 隐藏所有section
document.querySelectorAll('section').forEach(section => {
section.classList.remove('active-section');
});
// 显示目标section
const targetSection = document.querySelector(this.getAttribute('href'));
if (targetSection) {
targetSection.classList.add('active-section');
targetSection.scrollIntoView({
behavior: 'smooth'
});
}
});
});
// 添加页面加载欢迎信息
window.addEventListener('load', function() {
console.log("欢迎来到 Fortune Club!");
});
// 添加页面滚动效果
window.addEventListener('scroll', function() {
const sections = document.querySelectorAll('section');
sections.forEach(section => {
const rect = section.getBoundingClientRect();
if (rect.top >= 0 && rect.top <= window.innerHeight) {
section.style.opacity = '1';
section.style.transform = 'translateY(0)';
}
});
});
// 初始化页面动画
document.addEventListener('DOMContentLoaded', function() {
const sections = document.querySelectorAll('section');
sections.forEach(section => {
section.style.opacity = '0';
section.style.transform = 'translateY(20px)';
section.style.transition = 'all 0.5s ease-in-out';
});
});
// 搜索快捷键
document.addEventListener('keydown', function(e) {
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
e.preventDefault();
document.querySelector('.search-bar input').focus();
}
});
// 页面滚动时的动画效果
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('fade-in');
}
});
}, {
threshold: 0.1
});
document.querySelectorAll('section').forEach(section => {
section.classList.add('fade-out');
observer.observe(section);
});
// 初始化active状态
function updateActiveLink() {
const sections = document.querySelectorAll('section');
let currentSection = '';
sections.forEach(section => {
const rect = section.getBoundingClientRect();
if (rect.top <= 150 && rect.bottom >= 150) {
currentSection = '#' + section.id;
}
});
document.querySelectorAll('nav a').forEach(a => {
a.classList.remove('active');
if (a.getAttribute('href') === currentSection) {
a.classList.add('active');
}
});
}
window.addEventListener('scroll', updateActiveLink);
// 初始化:确保第一个section可见
document.addEventListener('DOMContentLoaded', function() {
const firstSection = document.querySelector('section');
if (firstSection) {
firstSection.classList.add('active-section');
}
});
document.addEventListener('DOMContentLoaded', function() {
// 获取所有导航链接
const navLinks = document.querySelectorAll('nav a');
// 为每个链接添加点击事件
navLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
// 获取目标section的id
const targetId = this.getAttribute('href').substring(1);
// 隐藏所有section
document.querySelectorAll('main section').forEach(section => {
section.classList.remove('active-section');
section.style.opacity = '1'; // 重置透明度
section.style.transform = 'none'; // 重置变换
});
// 显示目标section
const targetSection = document.getElementById(targetId);
if (targetSection) {
targetSection.classList.add('active-section');
}
// 更新活动链接样式
navLinks.forEach(navLink => {
navLink.classList.remove('active');
});
this.classList.add('active');
});
});
// 初始化:确保第一个section可见并重置样式
const firstSection = document.querySelector('#fortune-club');
if (firstSection) {
firstSection.classList.add('active-section');
firstSection.style.opacity = '1';
firstSection.style.transform = 'none';
}
});
// 在现有代码后添加导航按钮功能
document.addEventListener('DOMContentLoaded', function() {
const sections = [
'fortune-club',
'fortune-alpha',
'新人必读',
'小白入门',
'金狗秘籍',
'复盘日记',
'好文分享',
'工具推荐',
'注意安全'
];
function updateNavButtons() {
const currentSection = document.querySelector('section.active-section');
const currentIndex = sections.indexOf(currentSection.id);
// 移除旧的导航按钮
const oldNav = currentSection.querySelector('.page-navigation');
if (oldNav) oldNav.remove();
// 创建新的导航按钮
const navHTML = `
<div class="page-navigation">
<div class="nav-buttons">
<a class="nav-button prev">
<div class="nav-content">
<span class="nav-direction">Previous</span>
<span class="nav-title"></span>
</div>
</a>
<a class="nav-button next">
<div class="nav-content">
<span class="nav-direction">Next</span>
<span class="nav-title"></span>
</div>
</a>
</div>
</div>
`;
currentSection.insertAdjacentHTML('beforeend', navHTML);
const prevButton = currentSection.querySelector('.nav-button.prev');
const nextButton = currentSection.querySelector('.nav-button.next');
// 更新按钮状态和内容
if (currentIndex > 0) {
const prevSection = document.getElementById(sections[currentIndex - 1]);
prevButton.style.display = 'flex';
prevButton.querySelector('.nav-title').textContent = prevSection.querySelector('h1, h2').textContent;
prevButton.onclick = () => {
document.querySelector(`nav a[href="#${sections[currentIndex - 1]}"]`).click();
};
} else {
prevButton.style.display = 'none';
}
if (currentIndex < sections.length - 1) {
const nextSection = document.getElementById(sections[currentIndex + 1]);
nextButton.style.display = 'flex';
nextButton.querySelector('.nav-title').textContent = nextSection.querySelector('h1, h2').textContent;
nextButton.onclick = () => {
document.querySelector(`nav a[href="#${sections[currentIndex + 1]}"]`).click();
};
} else {
nextButton.style.display = 'none';
}
}
// 在section切换时更新导航按钮
const navLinks = document.querySelectorAll('nav a');
navLinks.forEach(link => {
link.addEventListener('click', () => {
setTimeout(updateNavButtons, 0);
});
});
// 初始化导航按钮
updateNavButtons();
});
// 添加滑动子目录相关的 JavaScript
document.addEventListener('DOMContentLoaded', function() {
const diaryNav = document.querySelector('.diary-nav-inner');
const prevBtn = document.querySelector('.diary-nav .prev');
const nextBtn = document.querySelector('.diary-nav .next');
const navItems = document.querySelectorAll('.diary-nav-item');
// 滚动按钮事件
prevBtn.addEventListener('click', () => {
diaryNav.scrollBy({
left: -200,
behavior: 'smooth'
});
});
nextBtn.addEventListener('click', () => {
diaryNav.scrollBy({
left: 200,
behavior: 'smooth'
});
});
// 点击导航项时添加高亮效果
navItems.forEach(item => {
item.addEventListener('click', (e) => {
e.preventDefault();
// 移除所有active类
navItems.forEach(i => i.classList.remove('active'));
// 添加active类到当前点击项
item.classList.add('active');
// 平滑滚动到目标位置
const targetId = item.getAttribute('href');
const targetElement = document.querySelector(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// 监听滚动,更新当前活动的导航项
const diaryEntries = document.querySelectorAll('.diary-entry');
window.addEventListener('scroll', () => {
let currentEntry = null;
diaryEntries.forEach(entry => {
const rect = entry.getBoundingClientRect();
if (rect.top <= 200 && rect.bottom >= 200) {
currentEntry = entry;
}
});
if (currentEntry) {
const currentId = `#${currentEntry.id}`;
navItems.forEach(item => {
if (item.getAttribute('href') === currentId) {
item.classList.add('active');
} else {
item.classList.remove('active');
}
});
}
});
});