-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathscript.js
More file actions
511 lines (433 loc) · 14.7 KB
/
script.js
File metadata and controls
511 lines (433 loc) · 14.7 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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
// 页面加载时执行
document.addEventListener('DOMContentLoaded', function() {
// 更新时间显示
updateTime();
// 每天午夜更新时间
setInterval(updateTime, 1000 * 60 * 60); // 每小时检查一次
// 平滑滚动
initSmoothScroll();
// 导航栏滚动效果
initNavbarScroll();
// 卡片hover效果增强
initCardEffects();
// 页面加载动画
initPageAnimations();
});
// 更新时间函数
function updateTime() {
const now = new Date();
const timeString = formatDate(now);
const updateTimeElement = document.getElementById('updateTime');
if (updateTimeElement) {
updateTimeElement.textContent = timeString;
}
}
// 格式化日期
function formatDate(date) {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
return `${year}年${month}月${day}日 ${hours}:${minutes}`;
}
// 平滑滚动
function initSmoothScroll() {
const links = document.querySelectorAll('a[href^="#"]');
links.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href').substring(1);
const targetElement = document.getElementById(targetId);
if (targetElement) {
const headerHeight = document.querySelector('.header').offsetHeight;
const targetPosition = targetElement.offsetTop - headerHeight - 20;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
}
// 导航栏滚动效果
function initNavbarScroll() {
const header = document.querySelector('.header');
let lastScrollTop = 0;
window.addEventListener('scroll', function() {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
if (scrollTop > 100) {
header.style.background = 'rgba(255, 255, 255, 0.95)';
header.style.backdropFilter = 'blur(10px)';
} else {
header.style.background = 'var(--white)';
header.style.backdropFilter = 'blur(10px)';
}
// 隐藏/显示导航栏
if (scrollTop > lastScrollTop && scrollTop > 200) {
header.style.transform = 'translateY(-100%)';
} else {
header.style.transform = 'translateY(0)';
}
lastScrollTop = scrollTop;
});
}
// 卡片效果增强
function initCardEffects() {
const cards = document.querySelectorAll('.feature-card, .artifact-card, .contact-card');
cards.forEach(card => {
card.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-8px) scale(1.02)';
});
card.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(0) scale(1)';
});
});
}
// 页面加载动画
function initPageAnimations() {
// 观察者API用于触发动画
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
});
// 为需要动画的元素添加观察
const animateElements = document.querySelectorAll('.feature-card, .artifact-card, .project-feature, .contact-card');
animateElements.forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(30px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(el);
});
}
// 添加粒子背景效果(可选)
function createParticleBackground() {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.style.position = 'fixed';
canvas.style.top = '0';
canvas.style.left = '0';
canvas.style.width = '100%';
canvas.style.height = '100%';
canvas.style.zIndex = '-1';
canvas.style.pointerEvents = 'none';
document.body.appendChild(canvas);
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
const particles = [];
const particleCount = 50;
// 创建粒子
for (let i = 0; i < particleCount; i++) {
particles.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
vx: (Math.random() - 0.5) * 0.5,
vy: (Math.random() - 0.5) * 0.5,
size: Math.random() * 2 + 1,
opacity: Math.random() * 0.5 + 0.1
});
}
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
particles.forEach(particle => {
// 更新位置
particle.x += particle.vx;
particle.y += particle.vy;
// 边界检测
if (particle.x < 0 || particle.x > canvas.width) particle.vx *= -1;
if (particle.y < 0 || particle.y > canvas.height) particle.vy *= -1;
// 绘制粒子
ctx.beginPath();
ctx.arc(particle.x, particle.y, particle.size, 0, Math.PI * 2);
ctx.fillStyle = `rgba(99, 102, 241, ${particle.opacity})`;
ctx.fill();
});
requestAnimationFrame(animate);
}
animate();
}
// 添加点击波纹效果
function addRippleEffect() {
const buttons = document.querySelectorAll('.btn, .artifact-link');
buttons.forEach(button => {
button.addEventListener('click', function(e) {
const ripple = document.createElement('span');
const rect = this.getBoundingClientRect();
const size = Math.max(rect.width, rect.height);
const x = e.clientX - rect.left - size / 2;
const y = e.clientY - rect.top - size / 2;
ripple.style.width = ripple.style.height = size + 'px';
ripple.style.left = x + 'px';
ripple.style.top = y + 'px';
ripple.classList.add('ripple');
this.appendChild(ripple);
setTimeout(() => {
ripple.remove();
}, 600);
});
});
}
// 添加CSS动画类
const style = document.createElement('style');
style.textContent = `
.ripple {
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, 0.6);
transform: scale(0);
animation: ripple-animation 0.6s linear;
pointer-events: none;
}
@keyframes ripple-animation {
to {
transform: scale(4);
opacity: 0;
}
}
.header {
transition: transform 0.3s ease, background 0.3s ease;
}
`;
document.head.appendChild(style);
// 初始化所有效果
window.addEventListener('load', function() {
addRippleEffect();
// createParticleBackground(); // 可选:启用粒子背景
});
// 添加键盘导航支持
document.addEventListener('keydown', function(e) {
if (e.key === 'Tab') {
document.body.classList.add('keyboard-navigation');
}
});
document.addEventListener('mousedown', function() {
document.body.classList.remove('keyboard-navigation');
});
// 添加深色模式切换(可选功能)
function initDarkMode() {
const darkModeToggle = document.createElement('button');
darkModeToggle.innerHTML = '<i class="fas fa-moon"></i>';
darkModeToggle.classList.add('dark-mode-toggle');
darkModeToggle.style.cssText = `
position: fixed;
top: 50%;
right: 20px;
transform: translateY(-50%);
background: var(--primary-color);
color: white;
border: none;
border-radius: 50%;
width: 50px;
height: 50px;
cursor: pointer;
box-shadow: var(--shadow-lg);
z-index: 1000;
transition: all 0.3s ease;
`;
darkModeToggle.addEventListener('click', function() {
document.body.classList.toggle('dark-mode');
const isDark = document.body.classList.contains('dark-mode');
this.innerHTML = isDark ? '<i class="fas fa-sun"></i>' : '<i class="fas fa-moon"></i>';
// 保存用户偏好
localStorage.setItem('darkMode', isDark);
});
// 检查用户偏好
if (localStorage.getItem('darkMode') === 'true') {
document.body.classList.add('dark-mode');
darkModeToggle.innerHTML = '<i class="fas fa-sun"></i>';
}
document.body.appendChild(darkModeToggle);
}
// 复制促销码功能
function copyPromoCode() {
const codeValue = document.getElementById('promoCode').textContent;
if (navigator.clipboard && window.isSecureContext) {
// 使用现代Clipboard API
navigator.clipboard.writeText(codeValue).then(() => {
showCopyNotification('授权码已复制到剪贴板!');
}).catch(() => {
fallbackCopyText(codeValue);
});
} else {
// 降级方案
fallbackCopyText(codeValue);
}
}
// 降级复制方案
function fallbackCopyText(text) {
const textarea = document.createElement('textarea');
textarea.value = text;
textarea.style.position = 'absolute';
textarea.style.left = '-9999px';
document.body.appendChild(textarea);
textarea.select();
try {
document.execCommand('copy');
showCopyNotification('授权码已复制到剪贴板!');
} catch (err) {
showCopyNotification('复制失败,请手动复制:' + text);
}
document.body.removeChild(textarea);
}
// 显示复制通知
function showCopyNotification(message) {
// 创建通知元素
const notification = document.createElement('div');
notification.textContent = message;
notification.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
background: var(--success-color);
color: white;
padding: 12px 20px;
border-radius: 8px;
font-weight: 500;
z-index: 10000;
box-shadow: var(--shadow-lg);
transform: translateX(100px);
opacity: 0;
transition: all 0.3s ease;
`;
document.body.appendChild(notification);
// 显示通知
setTimeout(() => {
notification.style.transform = 'translateX(0)';
notification.style.opacity = '1';
}, 100);
// 3秒后移除通知
setTimeout(() => {
notification.style.transform = 'translateX(100px)';
notification.style.opacity = '0';
setTimeout(() => {
if (notification.parentNode) {
notification.parentNode.removeChild(notification);
}
}, 300);
}, 3000);
}
// 添加滚动到顶部按钮
function addScrollToTopButton() {
const scrollBtn = document.createElement('button');
scrollBtn.innerHTML = '<i class="fas fa-chevron-up"></i>';
scrollBtn.className = 'scroll-to-top';
scrollBtn.style.cssText = `
position: fixed;
bottom: 30px;
right: 30px;
width: 50px;
height: 50px;
background: var(--primary-color);
color: white;
border: none;
border-radius: 50%;
cursor: pointer;
font-size: 18px;
box-shadow: var(--shadow-lg);
transition: all 0.3s ease;
z-index: 1000;
opacity: 0;
visibility: hidden;
transform: translateY(100px);
`;
document.body.appendChild(scrollBtn);
// 滚动时显示/隐藏按钮
window.addEventListener('scroll', debounce(() => {
if (window.pageYOffset > 300) {
scrollBtn.style.opacity = '1';
scrollBtn.style.visibility = 'visible';
scrollBtn.style.transform = 'translateY(0)';
} else {
scrollBtn.style.opacity = '0';
scrollBtn.style.visibility = 'hidden';
scrollBtn.style.transform = 'translateY(100px)';
}
}, 100));
// 点击滚动到顶部
scrollBtn.addEventListener('click', () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
// 悬浮效果
scrollBtn.addEventListener('mouseenter', () => {
scrollBtn.style.transform = 'translateY(0) scale(1.1)';
scrollBtn.style.background = 'var(--primary-dark)';
});
scrollBtn.addEventListener('mouseleave', () => {
scrollBtn.style.transform = 'translateY(0) scale(1)';
scrollBtn.style.background = 'var(--primary-color)';
});
}
// 增强的卡片动画
function enhanceCardAnimations() {
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry, index) => {
if (entry.isIntersecting) {
setTimeout(() => {
entry.target.classList.add('animate-in');
}, index * 100);
}
});
}, observerOptions);
// 观察所有卡片元素
const cards = document.querySelectorAll('.feature-card, .artifact-card, .comparison-card, .pricing-card');
cards.forEach(card => {
card.style.opacity = '0';
card.style.transform = 'translateY(30px)';
observer.observe(card);
});
}
// 添加CSS动画类
const enhancedStyle = document.createElement('style');
enhancedStyle.textContent = `
.animate-in {
opacity: 1 !important;
transform: translateY(0) !important;
transition: opacity 0.6s ease, transform 0.6s ease;
}
.scroll-to-top:hover {
box-shadow: var(--shadow-xl);
}
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.05); }
}
.pricing-card.featured {
animation: pulse 3s ease-in-out infinite;
}
`;
document.head.appendChild(enhancedStyle);
// 性能优化:防抖函数
function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
// 初始化增强功能
window.addEventListener('load', function() {
addScrollToTopButton();
enhanceCardAnimations();
});