From 063280b378e7d2c7b8a13e03b02b4eea97f15684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=C3=ABlle?= <125869653+anaelle1531@users.noreply.github.com> Date: Sat, 1 Feb 2025 15:56:39 +0100 Subject: [PATCH] Update index.js --- index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/index.js b/index.js index fcb9a31..20c7a7a 100644 --- a/index.js +++ b/index.js @@ -38,3 +38,19 @@ document.addEventListener("DOMContentLoaded", function () { science_img.setAttribute("src", "science1.jpg"); // modification d'un attribut de l'element HTML } }); + +document.addEventListener("DOMContentLoaded", function () { + let scrollToTopBtn = document.getElementById("scrollToTop"); + + window.addEventListener("scroll", function () { + if (window.scrollY > 300) { + scrollToTopBtn.style.display = "block"; + } else { + scrollToTopBtn.style.display = "none"; + } + }); + + scrollToTopBtn.addEventListener("click", function () { + window.scrollTo({ top: 0, behavior: "smooth" }); + }); +});