This is react component to allow use perfect-scrollbar in React.
Install the package npm install react-perfect-scrollbar
Add the stylesheet to your html:
<link rel='stylesheet' href='dist/css/perfect-scrollbar.css' />
Or import the css file if you have loader for css files:
import 'dist/css/perfect-scrollbar.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>
The following props are accepted:
The optional parameters used to initialize perfect-scrollbar. For more info, please refer to https://github.com/noraesae/perfect-scrollbar#optional-parameters
Invoked when the y-axis is scrolled in either direction.
Invoked when the x-axis is scrolled in either direction.
Invoked when scrolling upwards.
Invoked when scrolling downwards.
Invoked when scrolling to the left.
Invoked when scrolling to the right.
Invoked when scrolling reaches the start of the y-axis.
Invoked when scrolling reaches the end of the y-axis (useful for infinite scroll).
Invoked when scrolling reaches the start of the x-axis.
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>
There are some methods which can be called from the ref to this component:
set the scrollTop of the y-scrollbar
set the scrollLeft of the x-scrollbar
A working example can be found in the example
directory. Please run npm run example
and open http://localhost:8080/
in browser.
MIT