title: How to continuously scroll content within a DIV using jQuery?
body: <p><strong>Aim</strong></p>
  
  <p>The aim is to a have a container DIV with a fixed height and width and have the HTML content within that DIV automatically scroll vertically continuously.</p>
  
  <p><strong>Question</strong>
  Basically I've created the code below using jQuery to scroll (move) the child DIV vertically upwards until its outside the bounding parent box where the animation then completes which triggers an event handler which resets the position of the child DIV and starts the process again.</p>
  
  <p>This works fine, so the content scrolls up leaving a blank space and then starts from the bottom again and scrolls up.</p>
  
  <p>The problem I have is that the requirements for this is for the content to appear as if it was continuously repeating, see below diagram to better explain this, is there a way to do this? (I don't want to use 3rd party plug ins or libraries other than jQuery):</p>
  
  <p><a href="https://i.stack.imgur.com/3OAnL.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3OAnL.gif" alt="alt text"></a><br>
  <sub>(source: <a href="http://www.cameroncooke.com/playground/scrolling-example.gif" rel="nofollow noreferrer">cameroncooke.com</a>)</sub>  </p>
  
  <p><strong>What I have so far</strong></p>
  
  <p><em>The HTML:</em></p>
  
  <pre><code>&lt;div id="scrollingContainer"&gt;
  
    &lt;div class="scroller"&gt;
  
      &lt;h1&gt;This is a title&lt;/h1&gt;
  
      &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse at orci mi, id gravida tellus. Integer malesuada ante sit amet enim pulvinar congue. Donec pulvinar dolor et arcu posuere feugiat id et felis.&lt;/p&gt;
  
      &lt;p&gt;More content....&lt;/p&gt;   
  
    &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p><em>The CSS:</em></p>
  
  <pre><code>#scrollingContainer{
    height: 300px;
    width: 300px;
    overflow: hidden;
  }
  
  #scrollingContainer DIV.scroller{
    position: relative;
  }
  </code></pre>
  
  <p><em>The JavaScript:</em></p>
  
  <pre><code>/**
  * Scrolls the content DIV
  */
  function scroll() {
  
    if($('DIV.scroller').height() &gt;  $('#scrollingContainer').height()) {
  
      var t = $('DIV.scroller').position().top + $('DIV.scroller').height();
  
      /* Animate */
      $('DIV.scroller').animate(
      {
        top: '-=' + t + 'px'
      }
      , 4000, 'linear', animationComplete);
    }
  }
  
  function animationComplete() {
    $(this).css('top', $('#scrollingContainer').height());
    scroll();
  }
  </code></pre>