fianlly fixed STT button (window scroll event fixes)

This commit is contained in:
Nasir Anthony Montalvo
2026-03-09 01:40:49 -05:00
parent 077f9032b3
commit 774bc75735
2 changed files with 47 additions and 34 deletions

View File

@@ -1,35 +1,45 @@
<script>
// When the user scrolls down from the top of the document, show the button
window.onscroll = function () {
if (document.body.scrollTop > 500 || document.documentElement.scrollTop > 500) {
document.getElementById("scroll-to-top").style.display = "block";
} else {
document.getElementById("scroll-to-top").style.display = "none";
}
}
</script>
<a href="javascript:void(0)" id="scroll-to-top" class="btn btn-link" title="Back to Top">
<a href="#"
id="scroll-to-top"
class="btn btn-link"
title="Back to Top"
aria-label="Back to top">
<span class="visually-hidden">Back to top</span>
<svg class="bi icon-sprite" role="img" aria-label="Up Arrow">
<use xlink:href="{{ '/assets/css/cb-icons.svg' | relative_url }}#icon-back-to-top"/>
</svg>
</a>
<script>
const scrollBtn = document.getElementById("scroll-to-top");
(function() {
var btn = document.getElementById("scroll-to-top");
if (!btn) return;
window.addEventListener("scroll", function () {
if (window.scrollY > 500) {
scrollBtn.style.display = "block";
} else {
scrollBtn.style.display = "none";
function getScrolled() {
return window.scrollY
|| document.documentElement.scrollTop
|| document.body.scrollTop
|| 0;
}
});
scrollBtn.addEventListener("click", function () {
window.scrollTo({
top: 0,
left: 0,
behavior: "smooth"
});
});
function onScroll() {
btn.style.display = getScrolled() > 300 ? "block" : "none";
}
window.addEventListener("scroll", onScroll, { passive: true });
document.addEventListener("scroll", onScroll, { passive: true });
document.body.addEventListener("scroll", onScroll, { passive: true });
function scrollToTop(e) {
e.preventDefault();
e.stopPropagation();
try { window.scrollTo({ top: 0, behavior: "smooth" }); } catch(e) {}
try { document.documentElement.scrollTo({ top: 0, behavior: "smooth" }); } catch(e) {}
try { document.body.scrollTo({ top: 0, behavior: "smooth" }); } catch(e) {}
}
btn.addEventListener("click", scrollToTop);
btn.addEventListener("touchend", scrollToTop, { passive: false });
})();
</script>

View File

@@ -1265,7 +1265,7 @@ figure {
}
/* ============================================================================
SCROLL TO TOP - FULL STYLING (all viewports)
SCROLL TO TOP
============================================================================ */
#scroll-to-top {
@@ -1273,7 +1273,10 @@ figure {
bottom: 4.5rem;
right: 1rem;
z-index: 9999;
transition: transform 0.2s ease, box-shadow 0.2s ease;
display: none;
touch-action: manipulation;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
#scroll-to-top:hover {