fix(scroll-to-top): resolve overlap with buy me a coffee button

This commit is contained in:
ZhenShuo Leo
2025-07-25 03:52:54 +08:00
parent 019388def8
commit b777d4e59e
4 changed files with 53 additions and 24 deletions

View File

@@ -0,0 +1,13 @@
function scrollToTop() {
const scrollToTop = document.getElementById("scroll-to-top");
if (window.scrollY > window.innerHeight * 0.5) {
scrollToTop.classList.remove("translate-y-4", "opacity-0");
scrollToTop.classList.add("translate-y-0", "opacity-100");
} else {
scrollToTop.classList.remove("translate-y-0", "opacity-100");
scrollToTop.classList.add("translate-y-4", "opacity-0");
}
}
window.addEventListener("scroll", scrollToTop);
window.addEventListener("load", scrollToTop);