Find the Page Scrolling Position using jQuery

Leave a Comment

jQuery provides two functions that let you determine how much the page has scrolled from the top and from the left. To determine how much of the document is above the browser window, use this code:
$(document).scrollTop()

To determine how much of the document is off the screen to the left, use this code:
$(document).scrollLeft()

Both functions return a pixel value that you can use to position another element on the page.

For example, if you want to position a pop-up window in the center of the page, even after someone has scrolled down, you need to determine how far down the visitor has scrolled and move the pop-up window that many additional pixels down the page.

0 comments:

Post a Comment