forked from drowl87/hextra_mirror
fix: skip scroll event if no backToTop element (#138)
This commit is contained in:
parent
96c6ff073f
commit
cb09b7ce1e
@ -1,18 +1,22 @@
|
||||
const backToTop = document.querySelector("#backToTop");
|
||||
// Back to top button
|
||||
|
||||
document.addEventListener("scroll", (event) => {
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const backToTop = document.querySelector("#backToTop");
|
||||
if (backToTop) {
|
||||
document.addEventListener("scroll", (e) => {
|
||||
if (window.scrollY > 300) {
|
||||
backToTop.classList.remove("opacity-0");
|
||||
} else {
|
||||
backToTop.classList.add("opacity-0");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
function scrollUp() {
|
||||
window.scroll({
|
||||
top: 0,
|
||||
left: 0,
|
||||
behavior: 'smooth'
|
||||
behavior: "smooth",
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user