-
Notifications
You must be signed in to change notification settings - Fork 0
/
test1.html
103 lines (89 loc) · 2.16 KB
/
test1.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Smooth Scroll with Sticky Navbar</title>
<style>
body {
margin: 0;
padding: 0;
font-family: 'Arial', sans-serif;
scroll-behavior: smooth;
}
#zib {
position: sticky;
top: 0;
width: 85%;
margin: 10px;
height: 200px;
background-color: white;
border-radius: 10px;
padding: 15px;
transition: top 0.3s ease-in-out; /* 添加过渡效果 */
}
#zib-2 {
padding-left: 10px;
margin-top: 10px;
}
.zib-3 {
padding: 20px 10px 20px 0;
border-left: 1px #f5f6f7 solid;
position: relative;
}
.zib-3 li {
height: 33px;
margin-left: 10px;
position: relative;
transition: .3s;
border-radius: 5px;
}
.zib-3 li a {
color: #4e5358;
padding-left: 40px !important;
padding: 10px;
line-height: 33px;
font-size: 12px;
transition: .3s;
}
.zib-3 li:hover {
background-color: #f5f6f7;
}
.zib-3 li:hover.n a {
color: #eb71aa;
}
.zib-3 li:hover::before {
opacity: 1;
}
.active::before {
opacity: 1;
}
</style>
</head>
<body>
<div id="zib">
<div id="zib-2">
<ul class="zib-3">
<li class="n active"><a href="#wznav_0">游戏截图</a></li>
<li class="n"><a href="#wznav_1">游戏介绍</a></li>
<li class="n"><a href="#wznav_2">备注</a></li>
<li class="n"><a href="#wznav_3">下载链接</a></li>
</ul>
</div>
</div>
<!-- 添加一些占位元素以便滚动 -->
<div style="height: 1000px;"></div>
<script>
window.addEventListener('scroll', function() {
const zib = document.querySelector('#zib');
const scrollPosition = window.scrollY;
// 根据滚动位置决定导航栏是否粘性滚动
if (scrollPosition === 0) {
zib.style.top = '0';
} else {
zib.style.top = `${scrollPosition}px`;
}
});
</script>
</body>
</html>