How to detect if user has reached almost the end of the page using jQuery?
<p>Right now I fire an event when the user has reached the bottom of the page using this:</p>

<pre><code>$(window).scroll(function() {       
    if($(window).scrollTop() == $(document).height() - $(window).height()) {
        // do something
    }
});
</code></pre>

<p>How can this be modified to fire the event when the user reached almost the end of the page, let's say 300px left?</p>
