title: popstate - need to click twice on back button to actually get back
body: <p>I'm creating a single-page and using pushState to change the adress. Now, if I push back, popstate is fired and I want to animate the page scrolling from the current position to the last position. That works, of course, but the page jumps to the top.</p>
  
  <p>Does anyone know how to prevent that behavior? I'm using jQuery to animate the scrolling....</p>
  
  <p>Thanks :)</p>
  
  <p><strong>// edit:</strong> ok I found out, if I animate the scrolling and then changing the url, it won't jump around - but now I have to double-press the back button to get back...<br>
  <a href="http://www.testwebseiten.at/user/falk/stein-jagersbacher.at" rel="noreferrer">http://www.testwebseiten.at/user/falk/stein-jagersbacher.at</a></p>
  
  <p>The code is a little messy so I explain it a little:</p>
  
  <pre><code>    var scrollCurrentSection = function(event) {
          if (typeof event.preventDefault != 'undefined')
              event.preventDefault();
  
          var page = "";
          if (window.location.href.substr(-1) == '/')
              page = sjag.index;
          else
              page = window.location.href.match(/([^\/]+)$/)[1];
  
          $this       = $('a[href$="'+page+'"]');
          if ($this.length) {
              sjag.scrollToSection($this);
          }
      }
      window.onpopstate = scrollCurrentSection;
  </code></pre>
  
  <p>The sjag contains several options and methods... so <code>sjag.index</code> contains just 'index.php', <code>sjag.scrollToSection</code> contains the animation.</p>
  
  <p>On clicking a link of the navigation, the following function gets called:</p>
  
  <pre><code>    // set navi
      $("#navi a, #navi-add a").click(function(event) {
          var data = $(this).data('sjagpage');
          if (typeof data == 'undefined')
              return;
  
          event.preventDefault();
          // animate scrolling
          $this   = $(this);
          sjag.scrollToSection($(this), function() {
              history.pushState("", "", $this.attr('href'));
          });
      });
  </code></pre>
  
  <p><code>$(this).data('sjagpage')</code> contains the jQuery-element.</p>
  
  <p>When I don't animate the scrolling it only needs one click to get back - but when I now animate it, it needs two... why?</p>