From ccba711576c1c12cc1edc235c29a4a3635bf9400 Mon Sep 17 00:00:00 2001 From: FURK4NGG <105324908+FURK4NGG@users.noreply.github.com> Date: Wed, 11 Sep 2024 14:33:27 +0300 Subject: [PATCH] Update 1.js --- JAVASCRIPT/tr/1.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/JAVASCRIPT/tr/1.js b/JAVASCRIPT/tr/1.js index 8230480..f81c7a1 100644 --- a/JAVASCRIPT/tr/1.js +++ b/JAVASCRIPT/tr/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() {