nopaque/web/app/static/js/modules/nopaque.scrollToTop.js

21 lines
642 B
JavaScript
Raw Normal View History

2020-08-20 14:03:37 +00:00
/**
* Function to show a scrol lto top button if the user has scrolled down
* 250 pixels from teh headline element.
*/
function scrollToTop() {
let headline = document.querySelector(".headline");
let scrollToTop = document.querySelector("#menu-scroll-to-top-div");
window.addEventListener("scroll", (event) => {
if (pageYOffset > 250) {
scrollToTop.classList.toggle("hide", false);
} else {
scrollToTop.classList.toggle("hide", true);
}
});
scrollToTop.onclick = () => {
headline.scrollIntoView({behavior: "smooth", block: "end", inline: "nearest"});
};
}
// export function
export { scrollToTop };