Code Monkey home page Code Monkey logo

react-perfect-scrollbar's Introduction

React-Perfect-Scrollbar Build Status npm npm downloads

This is react component to allow use perfect-scrollbar in React.

To read documentation for versions < 1.0, please visit v0.2.5.

Usage

Install the package npm install react-perfect-scrollbar -S Import the css file if you have loader for css files:

    import 'react-perfect-scrollbar/dist/css/styles.css';

Import the module in the place you want to use:

    import PerfectScrollbar from 'react-perfect-scrollbar'

Wrap you content in this component:

    <PerfectScrollbar>
        ... SCROLLBAR CONTENT HERE ...
    </PerfectScrollbar>

Props

The following props are accepted:

option

The optional parameters used to initialize perfect-scrollbar. For more info, please refer to https://github.com/noraesae/perfect-scrollbar#optional-parameters

containerRef

Return the container ref: (ref) => void; If you want to scroll to somewhere, just update scrollTop/scrollLeft by the ref:

// Suppose you have save the containerRef to this._scrollRef
// change scroll top
this._scrollRef.scrollTop = 0;

// change scroll left
this._scrollRef.scrollLeft = 0;

onScrollY

Invoked when the y-axis is scrolled in either direction.

onScrollX

Invoked when the x-axis is scrolled in either direction.

onScrollUp

Invoked when scrolling upwards.

onScrollDown

Invoked when scrolling downwards.

onScrollLeft

Invoked when scrolling to the left.

onScrollRight

Invoked when scrolling to the right.

onYReachStart

Invoked when scrolling reaches the start of the y-axis.

onYReachEnd

Invoked when scrolling reaches the end of the y-axis (useful for infinite scroll).

onXReachStart

Invoked when scrolling reaches the start of the x-axis.

onXReachEnd

Invoked when scrolling reaches the end of the x-axis.

All the callback 'onXXXX' can accept a parameter: the ref to the scrollbar container. You can get the current scrollTop and scrollLeft from it:

    <PerfectScrollbar
        onScrollY={container => console.log(`scrolled to: ${container.scrollTop}.`)}>
        ... SCROLLBAR CONTENT HERE ...
    </PerfectScrollbar>

Methods

There are no more methods on components. You should update the scroll position by using the containerRef.

Example

A working example can be found in the example directory. Please run npm run example in browser. (Must run npm run build for the first time)

License

MIT

react-perfect-scrollbar's People

Contributors

goldenyz avatar yangzhou01 avatar patrykkopycinski avatar phil-dileo avatar patresi avatar

Watchers

Marcelo Jorge Vieira 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.