Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back to top arrow #2

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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