-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathside-nav-bar.html
74 lines (67 loc) · 1.8 KB
/
side-nav-bar.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!--360 浏览器在读取到这个标签后,立即切换对应的极速核-->
<meta name="renderer" content="webkit">
<!--优先使用 IE 最新版本和 Chrome-->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<!--缩放比例为1-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0,user-scalable=no">
<title>侧边浮动导航栏</title>
<style>
* {
margin: 0;
padding: 0;
}
body{
height: 1600px;
overflow-y: auto;
}
ul{
position: absolute;
left: 0;
top: 100px;
height: 120px;
width: 60px;
color: #333;
font-size: 14px;
list-style: none;
}
ul.fixed{
position: fixed;
top: 0;
}
ul li{
float: left;
line-height: 40px;
border-bottom: 1px solid #ccc;
width: 100%;
text-align: center;
background-color: #eee;
}
</style>
</head>
<body>
<ul class="">
<li>首页</li>
<li>关于</li>
<li>联系</li>
</ul>
</body>
<script src="./ready.js"></script>
<script>
document.ready(function () {
var sidebar = document.getElementsByTagName('ul')[0];
var top = sidebar.offsetTop;
window.addEventListener('scroll', function () {
var wtop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
if(wtop < top){
sidebar.classList.remove('fixed');
}else{
sidebar.classList.add('fixed');
}
})
});
</script>
</html>