-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
107 lines (94 loc) · 3.16 KB
/
Copy pathscript.js
File metadata and controls
107 lines (94 loc) · 3.16 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
// 标签页切换功能
const tabBtns = document.querySelectorAll('.tab-btn');
const contentGrids = document.querySelectorAll('.content-grid');
tabBtns.forEach(btn => {
btn.addEventListener('click', () => {
// 移除所有标签的active类
tabBtns.forEach(b => b.classList.remove('active'));
// 给当前点击的标签添加active类
btn.classList.add('active');
// 隐藏所有内容
contentGrids.forEach(grid => grid.classList.remove('active'));
// 显示对应的内容
const targetGrid = document.getElementById(`${btn.dataset.tab}-content`);
if (targetGrid) {
targetGrid.classList.add('active');
}
});
});
// 返回顶部按钮功能
const backToTopBtn = document.getElementById('back-to-top');
// 显示/隐藏返回顶部按钮
window.addEventListener('scroll', () => {
if (window.scrollY > 300) {
backToTopBtn.style.display = 'flex';
} else {
backToTopBtn.style.display = 'none';
}
});
// 点击返回顶部
backToTopBtn.addEventListener('click', () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
// 导航栏平滑滚动
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth'
});
}
});
});
// 页面加载时的渐入动画
document.addEventListener('DOMContentLoaded', () => {
const sections = document.querySelectorAll('section');
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
});
sections.forEach(section => {
section.style.opacity = '0';
section.style.transform = 'translateY(20px)';
section.style.transition = 'all 0.6s ease-out';
observer.observe(section);
});
// 为内容卡片添加渐入动画
const cards = document.querySelectorAll('.content-card');
cards.forEach((card, index) => {
card.style.opacity = '0';
card.style.transform = 'translateY(20px)';
card.style.transition = `all 0.6s ease-out ${index * 0.1}s`;
const cardObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, {
threshold: 0.1
});
cardObserver.observe(card);
});
});
// 导航栏滚动效果
const navbar = document.querySelector('.navbar');
window.addEventListener('scroll', () => {
if (window.scrollY > 100) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});