title: Meaning of $(window).scrollTop() == $(document).height() - $(window).height()
body: <p>The following code is used to detect if a user has scrolled to the bottom of the page and it works.</p>
  
  <pre><code>if($(window).scrollTop() == $(document).height() - $(window).height()){
  //do something
  }
  </code></pre>
  
  <p><strong>Problem:</strong></p>
  
  <p>I don't understand why you subtract the height of the window from the height of the document, then compare that to the scroll height to determine whether or not the bottom of the page has been reached. Why isn't it simply </p>
  
  <pre><code>if($(window).scrollTop() == $(document).height()){
  //do something
  }
  </code></pre>
  
  <p>or</p>
  
  <pre><code>if($(window).scrollTop() ==  $(window).height()){
  //do something
  }
  </code></pre>