From e9271c3ef1f21b2b4f4a03717f8f62beccd067bf Mon Sep 17 00:00:00 2001 From: Hoernschen Date: Mon, 8 Jan 2024 17:13:59 +0100 Subject: [PATCH] CHANGE use scrolllistener only when site is 1.5 times the screen size --- static/js/scroll.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/static/js/scroll.js b/static/js/scroll.js index 7e734d0..6fd7033 100644 --- a/static/js/scroll.js +++ b/static/js/scroll.js @@ -1,15 +1,16 @@ -window.addEventListener("scroll", () => { - var height = document.documentElement.scrollHeight; - if ((height / window.screen.availHeight ) > 1.5) { - var winScroll = document.body.scrollTop || document.documentElement.scrollTop; - height = height - document.documentElement.clientHeight; - var scrolled = (winScroll / height) * 100; - document.getElementById('progress').style.width = scrolled + "%"; +window.onload = (event) => { + if ((document.documentElement.scrollHeight / window.screen.availHeight ) > 1.5) { + window.addEventListener("scroll", () => { + var winScroll = document.body.scrollTop || document.documentElement.scrollTop; + var height = document.documentElement.scrollHeight - document.documentElement.clientHeight; + var scrolled = (winScroll / height) * 100; + document.getElementById('progress').style.width = scrolled + "%"; - const toTop = document.getElementById('totop'); + const toTop = document.getElementById('totop'); - if ((window.scrollY > 0 && !toTop.classList.contains("show")) || (window.scrollY <= 0 && toTop.classList.contains("show"))) { - toTop.classList.toggle("show"); - } + if ((window.scrollY > 0 && !toTop.classList.contains("show")) || (window.scrollY <= 0 && toTop.classList.contains("show"))) { + toTop.classList.toggle("show"); + } + }); } -}); \ No newline at end of file +} \ No newline at end of file