mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 17:25:44 +00:00
21 lines
642 B
JavaScript
21 lines
642 B
JavaScript
/**
|
|
* 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 }; |