0

Now I know I can use scrollTop(), but that gets me the amount of pixels from the top of the screen. Would it be possible to get the amount of px from the bottom part of the screen to top?

AndrewL64
  • 15,794
  • 8
  • 47
  • 79
Xeen
  • 6,955
  • 16
  • 60
  • 111

1 Answers1

2

Just assign a variable to a function with the properties similar to scrollTop (but opposite) like this:

$.fn.scrollBottom = function() { 
  return $(document).height() - this.scrollTop() - this.height(); 
};

Then just call it as follows:

$(window).scrollBottom();  //how many pixels below current view
$("#elem").scrollBottom(); //how many pixels below element

Via- Opposite of "scrollTop" in jQuery

Community
  • 1
  • 1
AndrewL64
  • 15,794
  • 8
  • 47
  • 79