Minimalistic but perfect custom scrollbar plugin
To read documentation for versions < 1.0, please visit
perfect-scrollbar is minimalistic but perfect (for me, and maybe for most developers) scrollbar plugin.
- No change on design layout
- No manipulation on DOM tree
- Use plain
- Scrollbar style is fully customizable
- Efficient update on layout change
I hope you love it!
It's on the GitHub Pages.
Table of Contents
- Before using perfect-scrollbar
- How to use
- IE Support
The best way to install and use perfect-scrollbar is with npm. It's registered as perfect-scrollbar.
$ npm install perfect-scrollbar
You can manually download perfect-scrollbar from Releases.
If you want to use the development version of the plugin, build from source manually. The development version may be unstable.
$ git clone https://github.com/utatti/perfect-scrollbar.git $ cd perfect-scrollbar $ npm install $ npm run build
You can fork the following JSFiddles for testing and experimenting purposes:
Sources not mentioned above are not maintained officially. If there are issues of the following sources, please ask and resolve in each repository.
Before using perfect-scrollbar
The following requirements should meet.
- the container must have a
- the container must be a normal container element.
The following requirements are included in the basic CSS, but please keep in mind when you'd like to change the CSS files.
- the container must have an
overflow: hiddencss style.
- the scrollbar's position must be
- the scrollbar-x must have
top, and the scrollbar-y must have
Finally, scroll hooking is generally considered as a bad practice, and perfect-scrollbar should be used carefully. Unless custom scroll is really needed, using browser-native scroll is always recommended.
perfect-scrollbar emulates some scrolls, but not all of the kinds. It also does not work in some situations. You can find these cases in Caveats. Basically, items listed in the caveats are hacky to implement and may not be implemented in the future. If the features are really needed, please consider using browser-native scroll.
How to use
First of all, please check if the container element meets the requirements and the main CSS is imported.
Import via ES modules:
Or in browser:
const container = document;const ps = container;// or just with selector stringconst ps = '#container';
It can be initialised with options.
const ps = '#container'wheelSpeed: 2wheelPropagation: trueminScrollbarLength: 20;
If the size of your container or content changes, call
If you want to destroy the scrollbar, use
ps;ps = null; // to make sure garbages are collected
If you want to scroll to somewhere, just update
const container = document;containerscrollTop = 0;
You can also get information about how to use the plugin from code in
It is a list of handlers to scroll the element.
['click-rail', 'drag-thumb', 'keyboard', 'wheel', 'touch']
The scroll speed applied to mousewheel event.
If this option is true, when the scroll reaches the end of the side, mousewheel event will be propagated to parent element.
If this option is true, swipe scrolling will be eased.
When set to an integer value, the thumb part of the scrollbar will not shrink below that number of pixels.
When set to an integer value, the thumb part of the scrollbar will not expand over that number of pixels.
This sets threashold for
ps--scrolling-y classes to
remain. In the default CSS, they make scrollbars shown regardless of hover
state. The unit is millisecond.
When set to true, and only one (vertical or horizontal) scrollbar is visible then both vertical and horizontal scrolling will affect the scrollbar.
When set to true, the scroll bar in X axis will not be available, regardless of the content width.
When set to true, the scroll bar in Y axis will not be available, regardless of the content height.
The number of pixels the content width can surpass the container width without enabling the X axis scroll bar. Allows some "wiggle room" or "offset break", so that X axis scroll bar is not enabled just because of a few pixels.
The number of pixels the content height can surpass the container height without enabling the Y axis scroll bar. Allows some "wiggle room" or "offset break", so that Y axis scroll bar is not enabled just because of a few pixels.
perfect-scrollbar dispatches custom events.
This event fires when the y-axis is scrolled in either direction.
This event fires when the x-axis is scrolled in either direction.
This event fires when scrolling upwards.
This event fires when scrolling downwards.
This event fires when scrolling to the left.
This event fires when scrolling to the right.
This event fires when scrolling reaches the start of the y-axis.
This event fires when scrolling reaches the end of the y-axis (useful for infinite scroll).
This event fires when scrolling reaches the start of the x-axis.
This event fires when scrolling reaches the end of the x-axis.
You can also watch the reach state via the
const ps = ...;console; // => 'start' or 'end' or nullconsole; // => 'start' or 'end' or null
If you have any idea to improve this project or any problem using this, please feel free to upload an issue.
For common problems, there is a FAQ wiki page. Please check the page before uploading an issue.
Also, the project is not actively maintained. No maintainer is paid, and most of us are busy on our professional or personal works. Please understand that it may take a while for an issue to be resolved. Uploading a PR would be the fastest way to fix an issue.
The plugin is developed to work in modern MS browsers including Edge and IE11, but may have some issues in IE11 mainly because of IE rendering bug concerning sync update on scroll properties. The problem is mentioned in Caveats too.
IE<11 is not supported, and patches to fix problems in IE<=10 will not be accepted. When old IEs should be supported, please fork the project and make modification locally.