diff options
| author | William Hergès <william@herges.fr> | 2025-08-10 13:27:49 +0200 |
|---|---|---|
| committer | William Hergès <william@herges.fr> | 2025-08-10 13:27:49 +0200 |
| commit | 5d703baed11f8f1b44df5ed7e03142cbdce839c5 (patch) | |
| tree | 7aa1ab32ca4b9b0c5d5643d3c28dba7ae0eccb1b /src/pages/index.astro | |
| parent | 3f800fb6724a15e6355b73304246a4711231d28f (diff) | |
refactor(background): use event listener instead of onload
Diffstat (limited to 'src/pages/index.astro')
| -rw-r--r-- | src/pages/index.astro | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/src/pages/index.astro b/src/pages/index.astro index 3d5da47..7d5ef28 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -163,23 +163,22 @@ import Base from "../layout/Base.astro"; </div> </section> </main> -</Base> - -<script is:inline defer> - const sections = document.querySelectorAll("section[data-scroll]"); - document.addEventListener("scroll", () => { - sections.forEach((section) => { - const rect = section.getBoundingClientRect(); - if ( - section.top + window.scrollY > window.scrollY || - (rect.bottom + +window.scrollY) * 2 < window.scrollY - ) - return; - const content = section.querySelector(".content"); - if (content == null || !(content instanceof HTMLElement)) - throw new Error(`Invalid section ${section}`); - const ratio = (window.scrollY - rect.top) / (rect.bottom - rect.top); - content.style.top = `${65 - ratio * 20}%`; + <script is:inline defer> + const sections = document.querySelectorAll("section[data-scroll]"); + document.addEventListener("scroll", () => { + sections.forEach((section) => { + const rect = section.getBoundingClientRect(); + if ( + section.top + window.scrollY > window.scrollY || + (rect.bottom + +window.scrollY) * 2 < window.scrollY + ) + return; + const content = section.querySelector(".content"); + if (content == null || !(content instanceof HTMLElement)) + throw new Error(`Invalid section ${section}`); + const ratio = (window.scrollY - rect.top) / (rect.bottom - rect.top); + content.style.top = `${65 - ratio * 20}%`; + }); }); - }); -</script> + </script> +</Base> |
