title: jQuery animate scrollTop goes up then back down
body: <p>I have a function that checks if there are any errors on the page and auto scrolls to them. The problem that I'm having is it scrolls up to them but then comes back down to where it was before. I'd like it to scroll up and stay there. </p>
  
  <pre><code>$(".submit_button").click(function (event) {
          event.preventDefault();
          var errorElements = $(".error").filter(":visible");
  
          if (errorElements.size() &gt; 0) {
              target_top = $(errorElements).offset().top;
              $('html, body').animate({
                  scrollTop: target_top
              }, 800);
          }
          return false;
      });
  </code></pre>