Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I determine height and scrolling position of window in jQuery?

I need to grab the height of the window and the scrolling offset in jQuery, but I haven't had any luck finding this in the jQuery docs or Google.

I'm 90% certain there's a way to access height and scrollTop for an element (presumably including the window), but I just can't find the specific reference.

like image 214
One Crayon Avatar asked Nov 19 '08 23:11

One Crayon


People also ask

How does jquery calculate window height?

Basically, $(window). height() give you the maximum height inside of the browser window (viewport), and $(document). height() gives you the height of the document inside of the browser. Most of the time, they will be exactly the same, even with scrollbars.

How do I know my scroll height?

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.

How do I know my scroll position?

To get or set the scroll position of an element, you follow these steps: First, select the element using the selecting methods such as querySelector() . Second, access the scroll position of the element via the scrollLeft and scrollTop properties.


1 Answers

From jQuery Docs:

const height = $(window).height(); const scrollTop = $(window).scrollTop(); 

http://api.jquery.com/scrollTop/
http://api.jquery.com/height/

like image 155
Pim Jager Avatar answered Oct 16 '22 13:10

Pim Jager