45 lines
1023 B
JavaScript
45 lines
1023 B
JavaScript
(function () {
|
|
"use strict";
|
|
|
|
var scrollTopButtons = document.querySelectorAll(".footer-scroll-top");
|
|
|
|
if (!scrollTopButtons.length) {
|
|
return;
|
|
}
|
|
|
|
function goToPageTop() {
|
|
window.scrollTo({
|
|
top: 0,
|
|
behavior: "smooth",
|
|
});
|
|
}
|
|
|
|
function updateButtonVisibility() {
|
|
var shouldShowButton = window.scrollY > 300;
|
|
|
|
scrollTopButtons.forEach(function (button) {
|
|
button.classList.toggle("active", shouldShowButton);
|
|
});
|
|
}
|
|
|
|
scrollTopButtons.forEach(function (button) {
|
|
button.setAttribute("role", "button");
|
|
button.setAttribute("tabindex", "0");
|
|
button.setAttribute("aria-label", "Scroll to top");
|
|
|
|
button.addEventListener("click", goToPageTop);
|
|
button.addEventListener("keydown", function (event) {
|
|
if (event.key === "Enter" || event.key === " ") {
|
|
event.preventDefault();
|
|
goToPageTop();
|
|
}
|
|
});
|
|
});
|
|
|
|
window.addEventListener("scroll", updateButtonVisibility, {
|
|
passive: true,
|
|
});
|
|
|
|
updateButtonVisibility();
|
|
})();
|