| ---
|
| import FloatingButton from "@/components/common/FloatingButton.astro";
|
| ---
|
|
|
|
|
| <FloatingButton
|
| id="back-to-top-btn"
|
| icon="material-symbols:keyboard-arrow-up-rounded"
|
| ariaLabel="Back to Top"
|
| onclick="backToTop()"
|
| class="hide"
|
| />
|
|
|
| <script is:raw is:inline>
|
| function backToTop() {
|
|
|
| window.scroll({ top: 0, behavior: "smooth" });
|
| }
|
|
|
|
|
| if (typeof window.BackToTopManager === "undefined") {
|
| window.BackToTopManager = class BackToTopManager {
|
| constructor() {
|
| this.button = document.getElementById("back-to-top-btn");
|
| this.init();
|
| }
|
|
|
| init() {
|
| if (!this.button) return;
|
|
|
| this.setupScrollListener();
|
| }
|
|
|
| setupScrollListener() {
|
| const updateVisibility = () => {
|
| const scrollTop =
|
| window.pageYOffset || document.documentElement.scrollTop;
|
|
|
|
|
| if (scrollTop > 200) {
|
| this.button.classList.remove("hide");
|
| } else {
|
| this.button.classList.add("hide");
|
| }
|
| };
|
|
|
| window.addEventListener("scroll", updateVisibility, { passive: true });
|
| }
|
| };
|
| }
|
|
|
|
|
| document.addEventListener("DOMContentLoaded", () => {
|
| new BackToTopManager();
|
| });
|
|
|
|
|
| if (document.readyState === "loading") {
|
| document.addEventListener("DOMContentLoaded", () => {
|
| new BackToTopManager();
|
| });
|
| } else {
|
| new BackToTopManager();
|
| }
|
| </script> |