Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why window.scrollY !== document.body.clientHeight @ maximum scroll point

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.

like image 670
ahmed korim Avatar asked Sep 23 '26 21:09

ahmed korim


2 Answers

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.

like image 53
Laura Durieux Avatar answered Sep 25 '26 10:09

Laura Durieux


See Element.clientHeight:

The Element.clientHeight read-only property is zero for elements with no CSS or inline layout boxes, otherwise it's the inner height of an element in pixels, including padding but not the horizontal scrollbar height, border, or margin.

clientHeight can be calculated as CSS height + CSS padding - height of horizontal scrollbar (if present).

There might be a margin assigned to the body.

like image 24
str Avatar answered Sep 25 '26 09:09

str



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!