From d1eee95c91f6caee7db00bf48680a77ae0abee76 Mon Sep 17 00:00:00 2001 From: athuler Date: Sat, 28 Oct 2023 17:00:36 -0500 Subject: [PATCH] Fix Horizontal Default Scroll --- index.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index a2f2a46..eceecbe 100644 --- a/index.php +++ b/index.php @@ -382,9 +382,21 @@ function connectAll() { function Scrolldown() { var rect = document.getElementById("title").getBoundingClientRect(); - console.log((rect.right+rect.left)/2); - console.log(document.body.scrollWidth); - window.scroll(document.body.scrollWidth*0.25,0); + + const maxWidth = document.body.scrollWidth - window.innerWidth; + console.log("% page " + (window.pageXOffset * 100) / maxWidth); + + //console.log("Rect x: " + rect.x); + console.log("Rect Left: " + rect.left); + console.log("Rect Right: " + rect.right); + console.log("Scroll Width: " + document.body.scrollWidth); + console.log("Screen Width: " + screen.width); + var scrollHorizDist = window.scrollX + rect.left - (rect.left + rect.right)/2; + var scrollHorizDist = window.scrollX + rect.left - rect.left; + var scrollHorizDist = (document.body.scrollWidth - window.innerWidth) / 2; + + console.log(scrollHorizDist); + window.scroll(scrollHorizDist,0); } window.onload = Scrolldown;