Skip to content

Commit

Permalink
Merge pull request #2 from JulienR1/feature/back-to-top
Browse files Browse the repository at this point in the history
Back to top arrow
  • Loading branch information
JulienR1 authored Jan 30, 2025
2 parents e5ce0dd + e135510 commit 9d3d67c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/web/src/components/TopArrow.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<a
href="#"
id="back-to-top"
title="Retour en haut"
class="fixed flex items-center justify-center w-10 h-10 bottom-6 right-6 group/back-to-top opacity-0 invisible data-[show=true]:visible data-[show=true]:opacity-100 transition-all select-none"
data-show="false"
>
<div class="absolute w-full h-full bg-black rounded-full opacity-80"></div>
<span
class="text-4xl text-slate-100 z-10 group-hover/back-to-top:-translate-y-1 transition-all material-symbols-outlined"
>
keyboard_arrow_up
</span>
</a>

<script>
document.addEventListener("DOMContentLoaded", function () {
const arrow = document.getElementById("back-to-top")!;

arrow.addEventListener("click", function (e) {
e.preventDefault();
window.scrollTo({ top: 0, behavior: "smooth" });
});

window.addEventListener("scroll", function () {
arrow.dataset.show = (window.scrollY >= 200).toString();
});
});
</script>
2 changes: 2 additions & 0 deletions packages/web/src/layouts/Layout.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
import Header from "../components/Header.astro";
import Footer from "../components/Footer.astro";
import TopArrow from "../components/TopArrow.astro";
---

<!doctype html>
Expand Down Expand Up @@ -39,6 +40,7 @@ import Footer from "../components/Footer.astro";
<slot />
</main>
<Footer />
<TopArrow />
</body>
</html>

Expand Down

0 comments on commit 9d3d67c

Please sign in to comment.