-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
40 lines (35 loc) · 1.34 KB
/
script.js
File metadata and controls
40 lines (35 loc) · 1.34 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
document.addEventListener('DOMContentLoaded', function() {
const backToTopButton = document.getElementById('back-to-top');
const mobileNavToggle = document.getElementById('mobile-nav-toggle');
const mobileNavClose = document.getElementById('mobile-nav-close');
const mobileNavOverlay = document.getElementById('mobile-nav-overlay');
// 显示/隐藏返回顶部按钮
window.addEventListener('scroll', function() {
if (window.pageYOffset > 300) {
backToTopButton.style.display = 'block';
} else {
backToTopButton.style.display = 'none';
}
});
// 点击返回顶部
backToTopButton.addEventListener('click', function() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
// 移动端导航栏切换
mobileNavToggle.addEventListener('click', function() {
mobileNavOverlay.classList.add('show');
});
mobileNavClose.addEventListener('click', function() {
mobileNavOverlay.classList.remove('show');
});
// 点击导航链接关闭遮罩层
const mobileNavLinks = document.querySelectorAll('.mobile-nav-overlay .city-nav a');
mobileNavLinks.forEach(link => {
link.addEventListener('click', function() {
mobileNavOverlay.classList.remove('show');
});
});
});