Refactor scroll-to-top mechanism

This commit is contained in:
Ferit Yiğit BALABAN
2022-07-27 23:46:08 +03:00
parent f0e80bac7b
commit 2c69d7a87f
2 changed files with 9 additions and 6 deletions

View File

@@ -270,7 +270,6 @@ a {
#scroll-to-top {
width: $px_scroll-to-top_size;
height: $px_scroll-to-top_size;
display: none;
position: fixed;
right: 25px;
bottom: 55px;

View File

@@ -1,10 +1,11 @@
const SCROLL_MIN = 100;
scroll_to_top = document.getElementById("scroll-to-top");
window.onscroll = function () {
if (document.documentElement.scrollTop > 100 || document.body.scrollTop > 100) {
scroll_to_top.style.display = "block";
function checkScroll() {
if (document.documentElement.scrollTop > SCROLL_MIN || document.body.scrollTop > SCROLL_MIN) {
scroll_to_top.style.visibility = "visible";
} else {
scroll_to_top.style.display = "none";
scroll_to_top.style.visibility = "hidden";
}
}
@@ -60,4 +61,7 @@ async function toggleDropdown() {
hideDropdown();
hideNavitems();
}
}
}
window.addEventListener('load', checkScroll);
window.addEventListener('scroll', checkScroll);