Code Monkey home page Code Monkey logo

scroll-behavior's Introduction

scroll-behavior Travis npm package

Scroll behaviors for use with history.

Coveralls Discord

Usage

Enhance your history object with one of the scroll behaviors in this library to get the desired scroll behavior after transitions.

import createHistory from 'history/lib/createBrowserHistory'
import useScroll from 'scroll-behavior/lib/useStandardScroll'

const history = useScroll(createHistory)()

Guide

Installation

$ npm install history scroll-behavior

You may also want to install React Router to obtain a complete routing solution for React that works with history.

Scroll behaviors

useScrollToTop

useScrollToTop scrolls to the top of the page after any transition.

This is not fully reliable for POP transitions.

useSimpleScroll

useSimpleScroll scrolls to the top of the page on PUSH and REPLACE transitions, while allowing the browser to manage scroll position for POP transitions.

This can give pretty good results with synchronous transitions on browsers like Chrome that don't update the scroll position until after they've notified history of the location change. It will not work as well when using asynchronous transitions or with browsers like Firefox that update the scroll position before emitting the location change.

useStandardScroll

useStandardScroll attempts to imitate native browser scroll behavior by recording updates to the window scroll position, then restoring the previous scroll position upon a POP transition.

Notes

  • Support for async transitions is currently very poor. Fixing this will require major breaking API changes in the future.

scroll-behavior's People

Contributors

taion avatar knowbody avatar

Watchers

Chetan Shenoy avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.