From e39239e43c6ac5d5962315ec58eaf7b9a32c98db Mon Sep 17 00:00:00 2001 From: FURK4NGG <105324908+FURK4NGG@users.noreply.github.com> Date: Wed, 11 Sep 2024 14:32:56 +0300 Subject: [PATCH] Update 1.js --- JAVASCRIPT/1.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/JAVASCRIPT/1.js b/JAVASCRIPT/1.js index 8c03b65..df2ee2d 100644 --- a/JAVASCRIPT/1.js +++ b/JAVASCRIPT/1.js @@ -82,15 +82,26 @@ if ('serviceWorker' in navigator) { }); } +/*TO-TOP BUTTON REVEALING*/ const toTop = document.querySelector(".to-top"); +const trandingSlideContent = document.querySelector(".tranding-slide-content"); window.addEventListener("scroll", () => { - if (window.pageYOffset > document.body.scrollHeight/2) { + const trandingSlideRect = trandingSlideContent.getBoundingClientRect(); + + // Divin ortasını hesapla + const trandingSlideMiddle = trandingSlideRect.top + (trandingSlideRect.height / 2); + + // Sayfanın kaydırma yüksekliği + const scrollPosition = window.scrollY + window.innerHeight; + + // Eğer scroll pozisyonu divin ortasını geçerse butonu göster + if (scrollPosition > trandingSlideMiddle + window.scrollY) { toTop.classList.add("active"); } else { toTop.classList.remove("active"); } -}) +}); /*when the window is reloading or loading*/ window.addEventListener('load', function() {