title: How do I stop the duration of the scrollTop
body: <p>The directive I have now works good enough so far, but not every page has the same height so I want to stop the duration when it is already at the bottom.</p>
  
  <p>This is the code of the directive:</p>
  
  <pre><code>function (scope, elem, attrs) {
          $(document).on('contentchanged', '#mainText',  function () {
              $("html, body").animate({
                  scrollTop: 0
              }, 0),
              $("html, body").animate({
                  scrollTop: $(window).height()
              }, 4000);
          });
      }
  </code></pre>
  
  <p>So for example at the first page the view is at the bottom it can't go any lower and when I go to the next page that is a bit lower it continuous scrolling down.</p>
  
  <p>My question is <strong>how can I stop it scrolling ?</strong></p>