CHANGE use scrolllistener only when site is 1.5 times the screen size

This commit is contained in:
Hoernschen 2024-01-08 17:13:59 +01:00
parent a2e23623d6
commit e9271c3ef1
Signed by: hoernschen
GPG key ID: 37591FAF4E6D3462

View file

@ -1,15 +1,16 @@
window.addEventListener("scroll", () => { window.onload = (event) => {
var height = document.documentElement.scrollHeight; if ((document.documentElement.scrollHeight / window.screen.availHeight ) > 1.5) {
if ((height / window.screen.availHeight ) > 1.5) { window.addEventListener("scroll", () => {
var winScroll = document.body.scrollTop || document.documentElement.scrollTop; var winScroll = document.body.scrollTop || document.documentElement.scrollTop;
height = height - document.documentElement.clientHeight; var height = document.documentElement.scrollHeight - document.documentElement.clientHeight;
var scrolled = (winScroll / height) * 100; var scrolled = (winScroll / height) * 100;
document.getElementById('progress').style.width = scrolled + "%"; 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"))) { if ((window.scrollY > 0 && !toTop.classList.contains("show")) || (window.scrollY <= 0 && toTop.classList.contains("show"))) {
toTop.classList.toggle("show"); toTop.classList.toggle("show");
} }
});
} }
}); }