-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01 scrollIntoView.html
49 lines (48 loc) · 1.53 KB
/
01 scrollIntoView.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Author" content=" ">
<title>Document</title>
<style type="text/css">
*{margin: 0;padding: 0;}
a{text-decoration: none;}
ul,li{list-style: none;}
body{font-size: 14px;font-family: "微软雅黑";height: 130vh;}
#up,#down{width: 120px;height: 30px;text-align: center;line-height: 30px;position: fixed;right: 10px;top: 330px;background: red;color: #fff;}
#down{top: 380px}
#wrap{height: 20vh;background: skyblue;margin-top: 100vh;}
</style>
</head>
<body>
<div id="wrap"></div>
<div id="up">up</div>
<div id="down">down</div>
<script type="text/javascript">
/*
IE 移动端的UC浏览器不支持
scrollIntoView
scrollIntoViewIfNeeded
*/
var b = document.getElementsByTagName("body")[0];
var wrap = document.getElementById("wrap");
var up = document.getElementById("up");
var down = document.getElementById("down");
up.addEventListener('click',function(){
// b.scrollIntoView(true);
wrap.scrollIntoView({
block: 'start',
behavior: 'smooth'
});
});
down.addEventListener('click',function(){
// b.scrollIntoView(false);
wrap.scrollIntoView({
block: 'end',
// auto instant smooth
behavior: 'smooth'
});
});
</script>
</body>
</html>