defunkt / jquery-pjax

pushState + ajax = pjax
https://pjax.herokuapp.com
MIT License
16.73k stars 1.97k forks source link

pjax:success not trigger when go back #689

Open moonscu opened 7 years ago

moonscu commented 7 years ago

I found that when using the browser to go back, "pjax:success" didn't trigger, causing you to not return to the original height, but to the top of the previous page. The following code not work:

    var scrollTo = options.scrollTo

    // Ensure browser scrolls to the element referenced by the URL anchor
    if (hash) {
      var name = decodeURIComponent(hash.slice(1))
      var target = document.getElementById(name) || document.getElementsByName(name)[0]
      if (target) scrollTo = $(target).offset().top
    }
irosadie commented 2 years ago

$(document).on('pjax:popstate', function(){ //detect goback })