-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
26 lines (22 loc) · 740 Bytes
/
main.js
File metadata and controls
26 lines (22 loc) · 740 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
// Get the button
var mybutton = document.getElementById("btn-scroll-to-top");
// When the user scrolls down 50px from the top of the document, show the button
window.onscroll = function () {
scrollFunction();
};
function scrollFunction() {
if (document.body.scrollTop > 50 || document.documentElement.scrollTop > 50) {
mybutton.style.display = "block";
} else {
mybutton.style.display = "none";
}
}
// When the user clicks on the button, scroll to the top of the document
mybutton.addEventListener("click", scrollToTop);
function scrollToTop() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
function toggleModal(modal_id) {
document.getElementById(modal_id).classList.toggle("hidden");
}