-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
360 lines (307 loc) · 11.1 KB
/
Copy pathscript.js
File metadata and controls
360 lines (307 loc) · 11.1 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
// ===== 页面加载完成后的初始化 =====
document.addEventListener('DOMContentLoaded', function() {
// 初始化所有功能
initNavbar();
initCarousel();
initSmoothScroll();
initBackToTop();
initMenuToggle();
initWechatButton();
});
// ===== 导航栏滚动效果 =====
function initNavbar() {
const navbar = document.querySelector('.navbar');
const scrollThreshold = 50;
window.addEventListener('scroll', function() {
if (window.scrollY > scrollThreshold) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});
// 初始检查
if (window.scrollY > scrollThreshold) {
navbar.classList.add('scrolled');
}
}
// ===== 轮播图功能 =====
function initCarousel() {
const carouselTrack = document.querySelector('.carousel-track');
const slides = document.querySelectorAll('.carousel-slide');
const indicators = document.querySelectorAll('.indicator');
const prevBtn = document.querySelector('.carousel-btn.prev');
const nextBtn = document.querySelector('.carousel-btn.next');
let currentSlide = 0;
const totalSlides = slides.length;
const slideInterval = 5000; // 5秒自动切换
let autoSlideTimer;
// 更新轮播位置
function updateCarousel() {
carouselTrack.style.transform = `translateX(-${currentSlide * 100}%)`;
// 更新指示点
indicators.forEach((indicator, index) => {
if (index === currentSlide) {
indicator.classList.add('active');
} else {
indicator.classList.remove('active');
}
});
// 更新幻灯片状态
slides.forEach((slide, index) => {
if (index === currentSlide) {
slide.classList.add('active');
} else {
slide.classList.remove('active');
}
});
}
// 下一张幻灯片
function nextSlide() {
currentSlide = (currentSlide + 1) % totalSlides;
updateCarousel();
resetAutoSlide();
}
// 上一张幻灯片
function prevSlide() {
currentSlide = (currentSlide - 1 + totalSlides) % totalSlides;
updateCarousel();
resetAutoSlide();
}
// 跳转到指定幻灯片
function goToSlide(index) {
currentSlide = index;
updateCarousel();
resetAutoSlide();
}
// 重置自动轮播计时器
function resetAutoSlide() {
clearInterval(autoSlideTimer);
autoSlideTimer = setInterval(nextSlide, slideInterval);
}
// 事件监听器
if (prevBtn) {
prevBtn.addEventListener('click', prevSlide);
}
if (nextBtn) {
nextBtn.addEventListener('click', nextSlide);
}
// 指示点点击事件
indicators.forEach((indicator, index) => {
indicator.addEventListener('click', () => goToSlide(index));
});
// 触摸滑动支持
let touchStartX = 0;
let touchEndX = 0;
carouselTrack.addEventListener('touchstart', (e) => {
touchStartX = e.changedTouches[0].screenX;
});
carouselTrack.addEventListener('touchend', (e) => {
touchEndX = e.changedTouches[0].screenX;
handleSwipe();
});
function handleSwipe() {
const swipeThreshold = 50;
const diff = touchStartX - touchEndX;
if (Math.abs(diff) > swipeThreshold) {
if (diff > 0) {
// 向左滑动,下一张
nextSlide();
} else {
// 向右滑动,上一张
prevSlide();
}
}
}
// 开始自动轮播
resetAutoSlide();
// 鼠标悬停时暂停自动轮播
const carousel = document.querySelector('.carousel');
if (carousel) {
carousel.addEventListener('mouseenter', () => {
clearInterval(autoSlideTimer);
});
carousel.addEventListener('mouseleave', () => {
resetAutoSlide();
});
}
}
// ===== 平滑滚动 =====
function initSmoothScroll() {
const navLinks = document.querySelectorAll('.nav-link');
navLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if (targetId === '#') return;
const targetElement = document.querySelector(targetId);
if (targetElement) {
// 更新导航链接状态
navLinks.forEach(navLink => navLink.classList.remove('active'));
this.classList.add('active');
// 平滑滚动到目标
window.scrollTo({
top: targetElement.offsetTop - 80,
behavior: 'smooth'
});
}
});
});
}
// ===== 回到顶部按钮 =====
function initBackToTop() {
const backToTopBtn = document.querySelector('.footer-bottom .back-to-top');
if (backToTopBtn) {
// 显示/隐藏按钮
window.addEventListener('scroll', function() {
if (window.scrollY > 300) {
backToTopBtn.style.opacity = '1';
backToTopBtn.style.visibility = 'visible';
} else {
backToTopBtn.style.opacity = '0';
backToTopBtn.style.visibility = 'hidden';
}
});
// 点击事件
backToTopBtn.addEventListener('click', function() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
// 初始状态
backToTopBtn.style.transition = 'opacity 0.3s ease, visibility 0.3s ease';
backToTopBtn.style.opacity = '0';
backToTopBtn.style.visibility = 'hidden';
}
}
// ===== 移动端菜单切换 =====
function initMenuToggle() {
const menuToggle = document.querySelector('.menu-toggle');
const navMenu = document.querySelector('.nav-menu');
if (menuToggle && navMenu) {
menuToggle.addEventListener('click', function() {
navMenu.classList.toggle('active');
this.setAttribute('aria-expanded', navMenu.classList.contains('active'));
// 切换图标
const icon = this.querySelector('i');
if (navMenu.classList.contains('active')) {
icon.classList.remove('fa-bars');
icon.classList.add('fa-times');
} else {
icon.classList.remove('fa-times');
icon.classList.add('fa-bars');
}
});
// 点击菜单项后关闭菜单(移动端)
const navLinks = document.querySelectorAll('.nav-link');
navLinks.forEach(link => {
link.addEventListener('click', function() {
if (window.innerWidth <= 768) {
navMenu.classList.remove('active');
menuToggle.querySelector('i').classList.remove('fa-times');
menuToggle.querySelector('i').classList.add('fa-bars');
menuToggle.setAttribute('aria-expanded', 'false');
}
});
});
// 窗口大小变化时重置菜单
window.addEventListener('resize', function() {
if (window.innerWidth > 768) {
navMenu.classList.remove('active');
menuToggle.querySelector('i').classList.remove('fa-times');
menuToggle.querySelector('i').classList.add('fa-bars');
menuToggle.setAttribute('aria-expanded', 'false');
}
});
}
}
// ===== 微信公众号按钮交互 =====
function initWechatButton() {
const wechatBtn = document.querySelector('.wechat-card.compact .wechat-btn');
const qrPlaceholder = document.querySelector('.wechat-card.compact .qr-placeholder');
if (wechatBtn && qrPlaceholder) {
wechatBtn.addEventListener('click', function() {
// 模拟二维码点击效果
qrPlaceholder.style.borderColor = 'var(--accent-color)';
qrPlaceholder.style.color = 'var(--accent-color)';
qrPlaceholder.style.transform = 'scale(1.05)';
// 显示提示信息
const originalText = qrPlaceholder.querySelector('span').textContent;
qrPlaceholder.querySelector('span').textContent = '请使用微信扫码关注';
// 3秒后恢复
setTimeout(() => {
qrPlaceholder.style.borderColor = '';
qrPlaceholder.style.color = '';
qrPlaceholder.style.transform = '';
qrPlaceholder.querySelector('span').textContent = originalText;
}, 3000);
// 按钮反馈效果
this.style.transform = 'scale(0.95)';
setTimeout(() => {
this.style.transform = '';
}, 200);
});
}
}
// ===== 社交链接悬停效果增强 =====
function initSocialLinks() {
const socialLinks = document.querySelectorAll('.social-link');
socialLinks.forEach(link => {
link.addEventListener('mouseenter', function() {
const icon = this.querySelector('i');
if (icon) {
icon.style.transform = 'rotate(10deg) scale(1.2)';
icon.style.transition = 'transform 0.3s ease';
}
});
link.addEventListener('mouseleave', function() {
const icon = this.querySelector('i');
if (icon) {
icon.style.transform = '';
}
});
});
}
// 初始化社交链接效果
initSocialLinks();
// ===== 页面加载动画 =====
window.addEventListener('load', function() {
// 添加页面加载完成类
document.body.classList.add('loaded');
// 轮播图入场动画
const carousel = document.querySelector('.carousel');
if (carousel) {
setTimeout(() => {
carousel.style.opacity = '1';
carousel.style.transform = 'translateY(0)';
}, 300);
}
// 初始设置
if (carousel) {
carousel.style.opacity = '0';
carousel.style.transform = 'translateY(20px)';
carousel.style.transition = 'opacity 0.8s ease, transform 0.8s ease';
}
});
// ===== 滚动动画 =====
function initScrollAnimations() {
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate-in');
}
});
}, observerOptions);
// 观察需要动画的元素
const animatedElements = document.querySelectorAll('.about-content, .wechat-card');
animatedElements.forEach(el => {
el.classList.add('animate-on-scroll');
observer.observe(el);
});
}
// 初始化滚动动画
initScrollAnimations();