Skip to content

Manually update the browser's scroll position when using pushState routing with abstract-state-router

Notifications You must be signed in to change notification settings

TehShrike/asr-scroll-position

Repository files navigation

Uses the browser history API to keep track of scroll position manually, since it turns out most browsers scroll position remembering doesn't work well if you render the page on the tick after a pushState happens.

  • On scroll/resize, update the current position in state
  • On old state, wait for stateChangeEnd, then scroll to the position from state
  • On new state, wait for stateChangeEnd, then scroll to the anchor if it exists, else scroll to top

Usage

const watchScrollPosition = require('asr-scroll-position')

watchScrollPosition(stateRouter)

License

WTFPL

About

Manually update the browser's scroll position when using pushState routing with abstract-state-router

Resources

Stars

Watchers

Forks

Packages

No packages published