Updated women leading the way section
This commit is contained in:
44
assets/javascript/scroll-to-top.js
Normal file
44
assets/javascript/scroll-to-top.js
Normal file
@@ -0,0 +1,44 @@
|
||||
(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();
|
||||
})();
|
||||
Reference in New Issue
Block a user