What's the equivalent to element.scrollHeight
for window
in plain vanilla Javascript? I'm trying to rewrite code to target window
or document
instead of the element
?
Converting this:
remaining = element.scrollHeight - (element.clientHeight + element.scrollTop);
Into this:
remaining = window.scrollHeight - (window.innerHeight + window.pageYOffset);
The scrollHeight property returns the height of an element including padding, but excluding borders, scrollbars, or margins. The scrollHeight property returns the height in pixels.
clientHeight = the height of an element + the vertical padding. offsetHeight = the height of the element + the vertical padding + the top and bottom borders + the horizontal scrollbar (if it's available).
To get the height of the scroll bar the offsetHeight of div is subtracted from the clientHeight of div. OffsetHeight = Height of an element + Scrollbar Height. ClientHeight = Height of an element. Height of scrollbar = offsetHeight – clientHeight.
document.documentElement.scrollHeight
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