-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
39 lines (32 loc) · 885 Bytes
/
test.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
<html>
<head>
<style>
body {
height: 600px;
width: 600px;
}
button {
position: fixed;
}
</style>
</head>
<body>
<p>Click the button to scroll the contents of body.</p>
<p><strong>Tip:</strong> Click the button many times to scroll the same amount each time.</p>
<button onclick="myFunction()">Scroll contents of body</button><br><br>
<script>
var h = document.documentElement;
window.onscroll = function(){
console.log(h.scrollTop);
}
function myFunction() {
var body = document.body; // For Safari
var html = document.documentElement; // Chrome, Firefox, IE and Opera places the overflow at the html level, unless else is specified. Therefore, we use the documentElement property for these browsers
body.scrollLeft += 30;
body.scrollTop += 10;
html.scrollLeft += 30;
html.scrollTop += 10;
}
</script>
</body>
</html>