Refactor scroll-to-top mechanism
This commit is contained in:
@@ -270,7 +270,6 @@ a {
|
|||||||
#scroll-to-top {
|
#scroll-to-top {
|
||||||
width: $px_scroll-to-top_size;
|
width: $px_scroll-to-top_size;
|
||||||
height: $px_scroll-to-top_size;
|
height: $px_scroll-to-top_size;
|
||||||
display: none;
|
|
||||||
position: fixed;
|
position: fixed;
|
||||||
right: 25px;
|
right: 25px;
|
||||||
bottom: 55px;
|
bottom: 55px;
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
|
const SCROLL_MIN = 100;
|
||||||
scroll_to_top = document.getElementById("scroll-to-top");
|
scroll_to_top = document.getElementById("scroll-to-top");
|
||||||
|
|
||||||
window.onscroll = function () {
|
function checkScroll() {
|
||||||
if (document.documentElement.scrollTop > 100 || document.body.scrollTop > 100) {
|
if (document.documentElement.scrollTop > SCROLL_MIN || document.body.scrollTop > SCROLL_MIN) {
|
||||||
scroll_to_top.style.display = "block";
|
scroll_to_top.style.visibility = "visible";
|
||||||
} else {
|
} else {
|
||||||
scroll_to_top.style.display = "none";
|
scroll_to_top.style.visibility = "hidden";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,4 +61,7 @@ async function toggleDropdown() {
|
|||||||
hideDropdown();
|
hideDropdown();
|
||||||
hideNavitems();
|
hideNavitems();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.addEventListener('load', checkScroll);
|
||||||
|
window.addEventListener('scroll', checkScroll);
|
||||||
Reference in New Issue
Block a user