Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of "element.scrollHeight" for "window" in Javascript?

Tags:

javascript

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);

like image 819
Steve Avatar asked May 19 '14 15:05

Steve


People also ask

What is scrollHeight in Javascript?

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.

What is offsetHeight and clientHeight?

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).

How do you find the scroll height of an element?

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.


1 Answers

document.documentElement.scrollHeight
like image 142
user3653148 Avatar answered Oct 06 '22 11:10

user3653148