From 7765de1c2669d46cb5755b497ea85dfc785ed336 Mon Sep 17 00:00:00 2001 From: Adam Scott Date: Wed, 14 Aug 2024 15:44:51 -0400 Subject: [PATCH] Add scroll to top functionnality --- assets/css/main.css | 6 +++- assets/css/releases/4.3.scss | 47 ++++++++++++++++++++++++++++++ assets/js/releases/4.3.mjs | 55 ++++++++++++++++++++++++++++++++++++ pages/releases/4.3.html | 6 +++- 4 files changed, 112 insertions(+), 2 deletions(-) diff --git a/assets/css/main.css b/assets/css/main.css index ad8e722543..7a59558d16 100644 --- a/assets/css/main.css +++ b/assets/css/main.css @@ -348,6 +348,10 @@ hr { border-top: 2px solid var(--base-color-text); } +main { + position: relative; +} + .intro-title { margin-top: 48px; margin-bottom: 48px; @@ -1558,4 +1562,4 @@ section.sponsors .grid { width: 100%; border: none; margin: 35px 0; -} \ No newline at end of file +} diff --git a/assets/css/releases/4.3.scss b/assets/css/releases/4.3.scss index 32b7ab530e..7ca4fcaed1 100644 --- a/assets/css/releases/4.3.scss +++ b/assets/css/releases/4.3.scss @@ -122,6 +122,53 @@ $donate-robot-size: 500px; } } +#scroll-to-top { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + z-index: 1; + pointer-events: none; + + --card-padding: #{r-get-desktop($card-padding)}; + @include is-mobile() { + --card-padding: #{r-get-mobile($card-padding)}; + } + + .link { + pointer-events: all; + position: fixed; + bottom: 0; + right: 0; + width: 50px; + height: 50px; + margin: var(--card-padding); + text-decoration: none; + background-color: white; + border-radius: var(--card-padding); + + display: flex; + align-items: center; + justify-content: center; + box-shadow: rgba(0,0,0,25%) 1px 1px 5px; + + color: black; + font-size: 1.5em; + + &:hover { + span { + text-decoration: underline; + } + } + + span { + transform: + translateY(-3px); + } + } +} + #foundation-donate { background-color: #EFF1F5; @include is-dark() { diff --git a/assets/js/releases/4.3.mjs b/assets/js/releases/4.3.mjs index 64c1a6fbf3..a381b1c4dc 100644 --- a/assets/js/releases/4.3.mjs +++ b/assets/js/releases/4.3.mjs @@ -274,3 +274,58 @@ const lazyVideoObserver = new IntersectionObserver((entries, observer) => { for (const lazyVideo of lazyVideos) { lazyVideoObserver.observe(lazyVideo); } + +// Show/hide the scroll-to-top button +const linksElement = document.querySelector("#links"); +const scrollToTopElement = document.querySelector("#scroll-to-top"); +let scrollToTopTween = null; +let scrollState = ""; +const showScrollToTop = () => { + if (scrollState === "show") { + return; + } + scrollState = "show"; + if (scrollToTopTween != null) { + scrollToTopTween.kill(); + } + scrollToTopElement.style.display = "block"; + scrollToTopTween = gsap.to(scrollToTopElement, { + opacity: 1, + duration: 0.5, + }); +}; +const hideScrollToTop = () => { + if (scrollState === "hide") { + return; + } + scrollState = "hide"; + if (scrollToTopTween != null) { + scrollToTopTween.kill(); + } + scrollToTopTween = gsap.to(scrollToTopElement, { + opacity: 0, + duration: 0.5, + onComplete: () => { + scrollToTopElement.style.display = "none"; + } + }); +}; +const scrollToTopObserver = new IntersectionObserver((entries, observer) => { + // requestAnimationFrame(animationFrameHandler); + const entry = entries[0]; + if (entry.isIntersecting) { + hideScrollToTop(); + console.log("intersecting"); + } else { + const rect = linksElement.getBoundingClientRect(); + console.log(rect); + if (rect.y > window.innerHeight) { + console.log("hide"); + hideScrollToTop(); + } else { + console.log("show"); + showScrollToTop(); + } + } +}); +scrollToTopObserver.observe(linksElement); diff --git a/pages/releases/4.3.html b/pages/releases/4.3.html index fdfd9f064d..1176d197ab 100644 --- a/pages/releases/4.3.html +++ b/pages/releases/4.3.html @@ -49,7 +49,7 @@ -
+
@@ -113,6 +113,10 @@

+
+ +
+