-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal-scroll.html
89 lines (80 loc) · 2.6 KB
/
local-scroll.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
<!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;
}
.fixed-box{
position: fixed;
top: 0;
bottom: 0;
height: 40px;
width: 100%;
background-color: green;
color: #fff;
font-size: 16px;
line-height: 40px;
text-align: center;
}
.fixed-btn{
position: fixed;
top: 40px;
bottom: 0;
height: 40px;
width: 100%;
background-color: orange;
color: #fff;
font-size: 16px;
line-height: 40px;
text-align: center;
z-index: 1;
}
.scroll-box{
height: 1600px;
overflow-y: scroll;
}
.scroll-container.elastic{
-webkit-overflow-scrolling: touch;
overflow-scrolling: touch;
}
</style>
</head>
<body>
<div class="fixed-box">scrollTop:<span class="number">0</span></div>
<div class="fixed-btn"><span class="event">添加</span><i>overflow-scrolling:touch</i></div>
<div class="scroll-container">
<div class="scroll-box"></div>
</div>
</body>
<script src="./ready.js"></script>
<script>
document.ready(function () {
window.addEventListener('scroll', function () {
var wtop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
document.getElementsByClassName('number')[0].innerText = wtop;
});
document.getElementsByClassName('fixed-btn')[0].addEventListener('click', function(){
var event = document.getElementsByClassName('event')[0];
var text = event.innerText;
var scrollCon = document.getElementsByClassName('scroll-container')[0];
if(text === '添加'){
scrollCon.setAttribute('class', 'scroll-container elastic');
event.innerText = '移除';
}else{
scrollCon.setAttribute('class', 'scroll-container');
event.innerText = '添加';
}
});
});
</script>
</html>