fianlly fixed STT button (window scroll event fixes)
This commit is contained in:
@@ -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">
|
||||
<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 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"
|
||||
});
|
||||
});
|
||||
</script>
|
||||
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>
|
||||
@@ -1265,15 +1265,18 @@ figure {
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
SCROLL TO TOP - FULL STYLING (all viewports)
|
||||
SCROLL TO TOP
|
||||
============================================================================ */
|
||||
|
||||
#scroll-to-top {
|
||||
position: fixed;
|
||||
bottom: 4.5rem;
|
||||
right: 1rem;
|
||||
z-index: 9999;
|
||||
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
||||
z-index: 9999;
|
||||
display: none;
|
||||
touch-action: manipulation;
|
||||
cursor: pointer;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
|
||||
#scroll-to-top:hover {
|
||||
|
||||
Reference in New Issue
Block a user