MoOx / pjax

Easily enable fast Ajax navigation on any website (using pushState + xhr)
MIT License
1.43k stars 124 forks source link

Is it possible to restore the scroll position at page refresh? #214

Open gapplef opened 5 years ago

gapplef commented 5 years ago

I'm using Hexo to generate my personal website, and the theme NexT I used provide PJAX support. After enable PJAX, the scroll position back to top of the page on every refresh. Is it possible to restore the scroll position at page refresh?

bjoernhasse commented 4 years ago

I am having the same issue. Does anyone have an idea how to fix it?

bjoernhasse commented 4 years ago

Okay I found the reason for this behavior:

Pjax sets scrollRestoration to 'manual': https://github.com/MoOx/pjax/blob/7940a6e3e595dae970f670b0abfc2cc03d74d614/index.js#L26

You can configure this by setting 'scrollRestoration' to false:

  new Pjax({
    scrollRestoration: false,
  });
gapplef commented 4 years ago

@bjoernhasse This solved my problem, thanks!

According to the README

scrollRestoration (Boolean, default: true) When set to true, Pjax will attempt to restore the scroll position when navigating backwards or forwards.

What does this mean?