Malasorte Malasorte - 6 months ago 17
jQuery Question

If document can be scrolled vertically by 200px or more run function

Using Jquery or plain Js I want to run a function on

document ready
, if the page has a vertical scrollbar and the ammount by wich the page can be scrolled is
200px
or larger.

Basically, I want to modify the code below so that it runs on
document ready
, not when the user actually scrolls.

$(document).ready(function(){
$(window).scroll(function(){
if ($(this).scrollTop() > 200) {
// do stuff
}
});
});

Answer

This is how i would do it.

$(document).ready(function() {
  if(($(document).height() - $(window).height()) > 200)
  {
     //Do something.
  }
});