-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_n1.html
76 lines (67 loc) · 1.93 KB
/
_n1.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
<!DOCTYPE html>
<html>
<head>
<title>Floating Buttons</title>
<style>
.floating-buttons {
position: fixed;
bottom: 20px;
right: 20px;
z-index: 9999;
}
.floating-buttons button {
display: none;
margin-bottom: 10px;
padding: 10px;
background-color: #b38a06;
color: #fff;
border: none;
cursor: pointer;
border-radius: 4px;
font-size: 16px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
transition: background-color 0.3s ease;
}
.floating-buttons button:hover {
background-color: #bb9a05;
}
</style>
</head>
<body>
<div class="floating-buttons">
<button id="topButton">Go to Top</button>
<button id="bottomButton">Go to Bottom</button>
</div>
<div class="content">
<h1>Sample Content</h1>
<p>This is some example content.</p>
<p>Scroll down to see the buttons.</p>
<p>Scroll to the bottom to hide the "Go to Bottom" button.</p>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
var topButton = document.getElementById('topButton');
var bottomButton = document.getElementById('bottomButton');
bottomButton.style.display = 'block';
window.addEventListener('scroll', function() {
if (window.pageYOffset > 0) {
topButton.style.display = 'block';
} else {
topButton.style.display = 'none';
}
if ((window.innerHeight + window.pageYOffset) >= document.body.offsetHeight) {
bottomButton.style.display = 'none';
} else {
bottomButton.style.display = 'block';
}
});
topButton.addEventListener('click', function() {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
bottomButton.addEventListener('click', function() {
window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
});
});
</script>
</body>
</html>