title: Maintain scroll position for a div based on scroll bar position
body: <p>I've got my code written <a href="http://jsfiddle.net/qSx3M/" rel="nofollow noreferrer">here</a>.</p>
  <pre><code>setInterval(
      function (data){
          var alreadyScrolled = $(&quot;#smallBox&quot;).height() &gt;= $(&quot;#smallBox&quot;).get()[0].scrollHeight;
          
          
          $(&quot;#smallBox&quot;).append(data + &quot;&lt;br /&gt;&quot;);
          if (alreadyScrolled) {
              $(&quot;#smallBox&quot;).scrollTop($(&quot;#smallBox&quot;).heightoffsetHeight)
          }
      },
      1000, 
      Date()
  );
  
  
  &lt;div id=&quot;largeBox&quot;&gt;
      &lt;div id=&quot;smallBox&quot;&gt;
      &lt;/div&gt;
      &lt;input /&gt;
  &lt;/div&gt;
  </code></pre>
  <p>What I'm trying to do is, detect if the scroll bar is at the bottom of the window, and if it is, append the new data into the div, then scroll back down to the bottom. In the event that the scroll isn't already at the bottom, do nothing.</p>
  <p>I'm not sure which parts of either the DOM or jquery API I can use to accomplish this, I've been trying multiple things and am somewhat stuck here, nothing seems to give me a value in terms of where the scroll bar is, and how much I can can scroll. A percent value would be awesome if I could just get that.</p>
  <p>I don't want to use any libraries outside of jQuery, this means no plugins either.</p>
  <p>I'm looking to get the same behavior we see in the SO chat rooms, except that it seems to be using the ScrollTo plugin to accomplish what it does.</p>
  <p><strong>Update.</strong></p>
  <p>I can't just use .height() and .scrollTop, they don't match up.</p>
  <p>See this:
  <a href="http://jsfiddle.net/qSx3M/6/" rel="nofollow noreferrer">http://jsfiddle.net/qSx3M/6/</a></p>