Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if webpage page is scrolled? [duplicate]

Is there any way in javascript to check if web page has been vertically scrolled? specially for Internet Explorer? I need to get the mouse position in IE but using jQuery event e.pageY it gives correct value when page is not scrolled but when page is scrolled down then it gives wrong position.

like image 795
Muzzammil Hussain Avatar asked Jun 19 '10 07:06

Muzzammil Hussain


People also ask

How do I know if my page is scrolled?

If you want to check whether the user has scrolled to the bottom of the page, you can use the scroll() jQuery event. The given code piece takes the top scroll of the window, so how much the page is scrolled down, it adds the height of the visible window and checks if it is equivalent to the height of the document.

How do I know if my browser window is scrolled to the top?

You can check if window. scrollY (the number of pixels the window has scrolled vertically) is equal to 0 . If you want to check if the window has been scrolled to its leftermost, you can check if window. scrollX (the number of pixels the window has scrolled horizontally) is equal to 0 .


2 Answers

In case any future googlers find this, the quick example is:

if(!$(window).scrollTop()) { //abuse 0 == false :)
  alert("You are at the top of this window");
}
like image 168
Nick Craver Avatar answered Sep 21 '22 02:09

Nick Craver


Check out this question if you are comfortable with using jQuery:

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

like image 29
Peter Jaric Avatar answered Sep 19 '22 02:09

Peter Jaric