This package has been deprecated

Author message:

Deprecated. Use scroll-restoration-polyfill for greater compatibility.

prevent-popstate-scroll

2.0.0 • Public • Published

prevent-popstate-scroll

Deprecated: use history.scrollRestoration and its polyfill instead, it has broader compatibility.

Prevent the scroll restoration caused by the popstate event or back/forward buttons. Demo

gzipped size Travis build status npm version

Warning: currently only working on Chrome and Safari. Firefox and IE will need a bit more work.

Usage

// Prevent the scroll, always
preventPopstateScroll.prevent();
 
// Stop preventing the scroll
preventPopstateScroll.allow();
 
// Prevent the scroll only once, for example before manually calling history.go(-1)
preventPopstateScroll.preventOnce();

With browserify

npm install --save prevent-popstate-scroll
var preventPopstateScroll = require('prevent-popstate-scroll');

Alternative usage in ES6

import {prevent, allow, preventOnce} from 'prevent-popstate-scroll';
 
prevent();
allow();
preventOnce();

or:

import preventPopstateScroll from 'prevent-popstate-scroll';
 
preventPopstateScroll(true);
preventPopstateScroll(false);

API

preventPopstateScroll.prevent()

Prevents the scroll restoration that normally happens after the popstate History event.

preventPopstateScroll.allow()

Restores the normal browser behavior.

preventPopstateScroll.preventOnce()

Prevents the scroll restoration only once. Useful before manipulating the history once (e.g. history.go(-1)), without changing the whole site's behavior.

Dependencies

Used on

  • http://away.gorving.com/ — to avoid scroll jumping when closing history-enabled lightboxes (i.e. closable via back button)

License

MIT © Federico Brigante

Package Sidebar

Install

npm i prevent-popstate-scroll

Weekly Downloads

0

Version

2.0.0

License

MIT

Last publish

Collaborators

  • fregante