Reputation: 67
I need to get the max number of pixel that scrolled in the page.
I've tried window.pageXOffset but it return the atual scrolled , I need the full size always
Upvotes: 1
Views: 60
Reputation: 899
Due to this link
EDIT: Congratulation you have solve it. I have include more example for you.
let scrollLength = document.documentElement.scrollWidth-document.documentElement.clientWidth
myFunction();
window.addEventListener('scroll', myFunction);
function myFunction() {
document.getElementById("demo").innerHTML = "Pos: "+window.pageXOffset+"/"+scrollLength;
}
body{
margin: 0;
width: 1000px;
color: lightgray;
}
#demo{
color: black;
position:fixed;
top:0;
right:0;
}
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<a id="demo">xxx</a>
Upvotes: 1
Reputation: 67
I just solve this using
document.documentElement.scrollWidth - document.documentElement.clientWidth;
Upvotes: 0