I run the if function when the user gets to the bottom of the page, which works just fine, as it looks
if($(window).scrollTop() + $(window).height() == $(document).height()) {}
However, I want it to run a little before the bottom - about 300 pixels earlier.
I tried
if($(window).scrollTop() + $(window).height() + 300 == $(document).height()) {}
and
if($(window).scrollTop() + $(window).height() == $(document).height() -300) {}
and all other options to no avail.
I also tried to include variables.
var plusheight = 300;
if($(window).scrollTop() + $(window).height() + plusheight == $(document).height()) {}
if($(window).scrollTop() + $(window).height() + $plusheight == $(document).height()) {}
if($(window).scrollTop() + $(window).height() + "plusheight" == $(document).height()) {}
What am I doing wrong?
source
share