-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
28 lines (23 loc) · 841 Bytes
/
app.js
File metadata and controls
28 lines (23 loc) · 841 Bytes
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
// Get the button
var mybutton = document.getElementById("myBtn");
// Get the Navbar
// When the user scroll down 20px from the top of the document show the button
window.onscroll = function() {
scrollFunction()
};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
mybutton.style.display = 'block';
}else if ( document.body.scrollTop > 50 || document.documentElement.scrollTop > 50) {
document.getElementById("navbar-list").style.top = "0";
}
else {
mybutton.style.display = 'none';
document.getElementById("navbar-list").style.top = "-50px";
}
}
// When the use click on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}