Update 1.js

This commit is contained in:
FURK4NGG
2024-09-11 14:33:27 +03:00
committed by GitHub
parent e39239e43c
commit ccba711576
+13 -2
View File
@@ -82,15 +82,26 @@ if ('serviceWorker' in navigator) {
}); });
} }
/*TO-TOP BUTTON REVEALING*/
const toTop = document.querySelector(".to-top"); const toTop = document.querySelector(".to-top");
const trandingSlideContent = document.querySelector(".tranding-slide-content");
window.addEventListener("scroll", () => { 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"); toTop.classList.add("active");
} else { } else {
toTop.classList.remove("active"); toTop.classList.remove("active");
} }
}) });
/*when the window is reloading or loading*/ /*when the window is reloading or loading*/
window.addEventListener('load', function() { window.addEventListener('load', function() {