Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
53 lines (46 loc) · 1.5 KB
/
Copy pathscript.js
File metadata and controls
53 lines (46 loc) · 1.5 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
// 平滑滚动到指定区块
function scrollToSection(sectionId) {
const element = document.getElementById(sectionId);
if (element) {
element.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
}
// 处理联系表单提交
function handleSubmit(event) {
event.preventDefault();
// 显示成功消息
alert('感谢您的留言!我会尽快回复您。');
// 清空表单
event.target.reset();
}
// 导航链接平滑滚动
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('attribute', 'href').substring(1);
scrollToSection(targetId);
});
});
// 页面滚动时添加导航栏阴影效果
window.addEventListener('scroll', function() {
const header = document.querySelector('header');
if (window.scrollY > 50) {
header.style.boxShadow = '0 2px 20px rgba(0,0,0,0.2)';
} else {
header.style.boxShadow = 'none';
}
});
// 页面加载完成后的动画效果
window.addEventListener('load', function() {
const heroContent = document.querySelector('.hero-content');
heroContent.style.opacity = '0';
heroContent.style.transform = 'translateY(20px)';
setTimeout(() => {
heroContent.style.transition = 'opacity 1s ease, transform 1s ease';
heroContent.style.opacity = '1';
heroContent.style.transform = 'translateY(0)';
}, 100);
});