原生CSS滚动效果

原生CSS滚动效果

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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CSS滚动</title>
<style type="text/css">
a {
display: inline-block;
width: 50px;
text-decoration: none;
}
nav, main {
display: block;
margin: 0 auto;
text-align: center;
}
nav {
width: 339px;
padding: 5px;
border: 1px solid black;
position: sticky;
top: 0;
}
main {
display: block;
width: 350px;
height: 200px;
overflow-y: scroll;
scroll-behavior: smooth;
}
div {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
font-size: 5em;
}
</style>
</head>
<body>
<nav>
<a href="#page-1">1</a>
<a href="#page-2">2</a>
<a href="#page-3">3</a>
<a href="#page-4">4</a>
<a href="#page-5">5</a>
</nav>
<main>
<div id="page-1">1</div>
<div id="page-2">2</div>
<div id="page-3">3</div>
<div id="page-4">4</div>
<div id="page-5">5</div>
</main>
</body>
</html>

原生CSS滚动效果
https://github.com/chergn/chergn.github.io/c69f763b1c25/
作者
全易
发布于
2024年3月28日
许可协议