Why isn't window maximum scroll equal to body height?
I am trying to do some effect with the friction between the maximum scroll and current scroll.
This is because window.scrollY will give you the coordinate of the left top corner. You will see that if you add the height of the window to window.scrollY at the max scrolling point, you will have the height.
Example :
My window has as an innerHeight of 599,
My body has a height of 1797,
The value of window.scrollY at the maximum scrolling point is 1198,
If I do 1198 + 599 I obtain 1797 that is the right height of my document.
1198 + 599 = 1797
Just keep in mind that the value of window.scrollY is in the top left corner of the document.
See Element.clientHeight:
The
Element.clientHeightread-only property is zero for elements with no CSS or inline layout boxes, otherwise it's the inner height of an element in pixels, includingpaddingbut not the horizontal scrollbarheight,border, ormargin.
clientHeightcan be calculated as CSSheight+ CSSpadding- height of horizontal scrollbar (if present).
There might be a margin assigned to the body.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With