title: Get actual height of document with jQuery
body: <p>I have a problem with my jQuery plugin, I want to display footer in specific way right before end of page. For this I get actual bottom position and compare it with height of entire body. </p>
  
  <p>But there is a problem jQuery function height() return bad value. For example I know that site has height of 5515px but function returns to me a value: 8142px</p>
  
  <p>I use the plugin mCustomScrollbar in few places on page, and I think that it may cause the problem. I can't disable it, because page has elements which require it to look good.</p>
  
  <p>My code:</p>
  
  <pre><code>(function($){
      $.fn.scrollingElements = function(){
          var height = $(window).height();
          var max_height = $(document).height();
          var prev_top = $(window).scrollTop();
          var prev_bottom = top + height;
          $(window).scroll(function(){
              var top = $(window).scrollTop();
              var bottom = top + height;
  
              console.log(max_height, bottom);
  
              if(prev_top &lt; height &amp;&amp; top &gt; height){
                  // console.log('show header', 'show sticky', 'show footer small');
              }
              if(prev_top &gt; height &amp;&amp; top &lt; height){
                  // console.log('hide header', 'hide sticky', 'hide footer');
              }
              if(prev_top &lt; 2*height &amp;&amp; top &gt; 2*height){
                  // console.log('show sroll top');
              }
              if(prev_top &gt; 2*height &amp;&amp; top &lt; 2*height){
                  // console.log('hide scroll top');
              }
  
              if(prev_bottom &lt; max_height - 100 &amp;&amp; bottom &gt; max_height - 100){
                  // console.log('show footer large');
              }
              if(prev_bottom &gt; max_height - 100 &amp;&amp; bottom &lt; max_height - 100){
                  // console.log('show footer small');
              }
  
              prev_top = top;
              prev_bottom = bottom;
  
          });
          $(window).resize(function(){
              height = $(window).height();
          });
      }
  })(jQuery);
  </code></pre>
  
  <p>Answering to Tommy Riordan: 
  changing $(document).height() to document.body.clientHeight didn't work still  getting bad results. Tried using $('body').height() with same effect.</p>