2014-08-31 08:35:43 +08:00
perfect-scrollbar [![Travis CI ](https://travis-ci.org/noraesae/perfect-scrollbar.svg?branch=master )](https://travis-ci.org/noraesae/perfect-scrollbar)
2012-11-06 20:17:47 +08:00
=================
2012-11-06 20:59:36 +08:00
Tiny but perfect jQuery scrollbar plugin
2012-11-10 03:22:33 +08:00
Why perfect-scrollbar?
2012-11-06 20:59:36 +08:00
------------------
2014-04-17 19:32:24 +08:00
I worked on a personal project recently, and I was trying to find the jQuery scrollbar plugin that's *perfect* . But there was no *perfect* scrollbar plugin. That's why I decided to make one.
2012-11-10 03:22:33 +08:00
2014-12-03 01:47:34 +08:00
perfect-scrollbar is very tiny but *perfect* (for me, and maybe for most developers) jQuery scrollbar plugin.
I hope you love it!
2012-11-10 03:22:33 +08:00
Demo: http://noraesae.github.com/perfect-scrollbar/
2014-04-17 19:32:24 +08:00
What does *perfect* mean?
2012-11-10 03:22:33 +08:00
---------------------
*perfect* means...
* There should be no css change on any original element.
* The scrollbar should not affect the original design layout.
* The design of the scrollbar should be (nearly) fully customizable.
* If the size of the container or the content changes, the scrollbar size and position should be able to change.
Then perfect-scrollbar is really *perfect* ?
-------------------------------------------
Yes! the only thing that's not *perfect* is my English.
* perfect-scrollbar has some requirements, but doesn't change or add any style on original elements.
* perfect-scrollbar is designed not to have width or height. It's fixed on the right and bottom side of the container.
* You can change nearly all css styles of the scrollbar. The scrollbar design has no dependency on scripts.
2014-12-03 01:47:34 +08:00
* perfect-scrollbar supports an 'update' function. Whenever you need to update the size or position of the scrollbar, just update.
* Additionally, perfect-scrollbar uses 'scrollTop' and 'scrollLeft', not absolute positioning or something messy.
2012-11-10 03:22:33 +08:00
It's cool, isn't it?
2014-03-10 15:26:50 +08:00
Install
-------
2014-12-03 01:47:34 +08:00
You can download the latest stable version with download links at [Github Page ](http://noraesae.github.io/perfect-scrollbar/ ). You also can find all releases at [Releases ](https://github.com/noraesae/perfect-scrollbar/releases ) page.
2014-03-10 15:26:50 +08:00
If you want to use the development version of the plugin, use the source files which are not minified. They're in the `src` directory. The development version may be unstable, but some known bugs can be fixed.
```
2014-10-22 04:43:07 +08:00
$ git clone https://github.com/noraesae/perfect-scrollbar.git
$ cd perfect-scrollbar/src
2014-03-10 15:26:50 +08:00
```
You can use [Bower ](http://bower.io/ ) to install the plugin. The plugin is registered as `perfect-scrollbar` .
```
2014-10-22 04:43:07 +08:00
$ bower install perfect-scrollbar
```
It's registered on [npm ](https://www.npmjs.org/package/perfect-scrollbar ) as `perfect-scrollbar` .
```
$ npm install perfect-scrollbar
2014-03-10 15:26:50 +08:00
```
2014-09-23 11:28:21 +08:00
You can also load it from [cdnjs ](http://cdnjs.com/ ). It is registered as [`jquery.perfect-scrollbar` ](http://www.cdnjs.com/libraries/jquery.perfect-scrollbar ).
2012-11-10 03:22:33 +08:00
Requirements
------------
2014-12-03 01:47:34 +08:00
To make this plugin *perfect* , some requirements were unavoidable. But, they're all very trivial and there is nothing to worry about.
2012-11-10 03:22:33 +08:00
* the container must have a 'position' css style.
2014-02-19 14:16:26 +08:00
* the container must have an 'overflow:hidden' css style.
2012-11-10 03:22:33 +08:00
* the scrollbar's position must be 'absolute'.
* the scrollbar-x must have a 'bottom' css style, and the scrollbar-y must have a 'right' css style.
2013-06-18 15:02:01 +08:00
2014-12-03 01:47:34 +08:00
The below requirement is for perfect-scrollbar < = 0.3.4
2013-06-18 15:02:01 +08:00
2014-12-03 01:47:34 +08:00
* there must be the *one* content element (like div) for the container.
2014-07-06 01:01:24 +08:00
2013-03-14 12:44:51 +08:00
Optional parameters
-------------------
perfect-scrollbar supports optional parameters.
### wheelSpeed
The scroll speed applied to mousewheel event.
2014-08-25 07:35:51 +08:00
**Default: 1**
2013-03-14 12:44:51 +08:00
### wheelPropagation
2014-12-02 19:38:54 +08:00
If this option is true, when the scroll reaches the end of the side, mousewheel event will be propagated to parent element.
2013-09-30 15:23:27 +08:00
**Default: false**
2013-03-14 12:44:51 +08:00
2014-12-02 19:38:54 +08:00
### swipePropagation
If this option is true, when the scroll reaches the end of the side, touch scrolling will be propagated to parent element.
**Default: true**
2014-07-06 01:01:24 +08:00
2013-07-18 00:53:02 +08:00
### minScrollbarLength
2013-08-01 00:33:10 +08:00
When set to an integer value, the thumb part of the scrollbar will not shrink below that number of pixels.
2014-07-17 01:55:58 +08:00
**Default: null**
### maxScrollbarLength
When set to an integer value, the thumb part of the scrollbar will not expand over that number of pixels.
2013-09-30 15:23:27 +08:00
**Default: null**
2013-09-28 06:53:57 +08:00
### useBothWheelAxes
2013-09-30 15:23:27 +08:00
When set to true, and only one (vertical or horizontal) scrollbar is visible then both vertical and horizontal scrolling will affect the scrollbar.
**Default: false**
2013-09-28 06:53:57 +08:00
2013-09-30 16:24:12 +08:00
### useKeyboard
When set to true, the scroll works with arrow keys on the keyboard. The element is scrolled only when the mouse cursor hovers the element.
**Default: true**
2013-11-07 04:20:30 +08:00
### suppressScrollX
2013-11-07 04:28:39 +08:00
When set to true, the scroll bar in X axis will not be available, regardless of the content width.
2013-11-07 04:20:30 +08:00
**Default: false**
### suppressScrollY
2013-11-07 04:28:39 +08:00
When set to true, the scroll bar in Y axis will not be available, regardless of the content height.
2013-11-07 04:20:30 +08:00
**Default: false**
### scrollXMarginOffset
2013-11-07 04:28:39 +08:00
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.
2013-11-07 04:20:30 +08:00
**Default: 0**
### scrollYMarginOffset
2013-11-07 04:28:39 +08:00
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.
2013-11-07 04:20:30 +08:00
**Default: 0**
2012-11-10 03:22:33 +08:00
How to Use
----------
```html
< style >
2014-07-09 22:26:54 +08:00
#Demo {
2014-09-30 04:18:05 +08:00
position: relative;
height: 100%; /* Or whatever you want (eg. 400px) */
2014-07-09 22:26:54 +08:00
overflow: hidden;
}
2012-11-10 03:22:33 +08:00
< / style >
< div id = 'Demo' >
< div >
...
< / div >
< / div >
```
When the html document is like above, just use like this:
```javascript
$('#Demo').perfectScrollbar();
```
2013-03-14 12:44:51 +08:00
With optional parameters:
```javascript
$("#Demo").perfectScrollbar({
wheelSpeed: 20,
2013-07-18 00:53:02 +08:00
wheelPropagation: true,
minScrollbarLength: 20
2013-03-14 12:44:51 +08:00
})
```
2012-11-10 03:22:33 +08:00
If the size of your container or content changes:
```javascript
$('#Demo').perfectScrollbar('update');
```
If you want to destory the scrollbar:
```javascript
$('#Demo').perfectScrollbar('destroy');
```
2013-01-28 13:00:49 +08:00
If you want to scroll to somewhere, just use scroll-top css and update.
```javascript
$("#Demo").scrollTop(0);
$("#Demo").perfectScrollbar('update');
```
2014-12-03 01:47:34 +08:00
Also you can get information about how to use the plugin from code in the `examples` directory of the source tree.
2013-09-30 15:23:27 +08:00
2012-11-10 03:22:33 +08:00
Contribution
------------
2014-12-03 01:47:34 +08:00
#### Please read [Contributing](https://github.com/noraesae/perfect-scrollbar/wiki/Contributing) in the wiki before making any contribution.
2013-06-15 23:01:23 +08:00
2012-11-10 03:22:33 +08:00
I *really* welcome contributions! Please feel free to fork and issue pull requests when...
* You have a very nice idea to improve this plugin!
* You found a bug!
* You're good at English and can help my bad English!
2013-06-16 17:28:37 +08:00
For IE problems, please refer to [IE Support ](https://github.com/noraesae/perfect-scrollbar#ie-support )
IE Support
----------
2014-12-03 01:47:34 +08:00
The plugin would work in IEs >= IE9 (not well, though).
2013-06-16 17:28:37 +08:00
2014-10-22 03:58:43 +08:00
**The patches to fix problems in IE< =8 won't be accepted.**
2013-06-16 17:28:37 +08:00
When old IEs should be supported, please fork the project and make patches personally.
2014-03-10 15:43:04 +08:00
Helpdesk
--------
If you have any idea to improve this project or any problem using this, please feel free to upload an [issue ](https://github.com/noraesae/perfect-scrollbar/issues ).
2014-12-03 01:47:34 +08:00
For common problems there is a [FAQ ](https://github.com/noraesae/perfect-scrollbar/wiki/FAQ ) wiki page. Please check the page before uploading an issue.
2014-10-31 10:49:07 +08:00
2012-11-10 03:22:33 +08:00
License
-------
2015-01-09 01:36:27 +08:00
The MIT License (MIT) Copyright (c) 2015 Hyunje Alex Jun and other contributors.
2012-11-10 03:22:33 +08:00
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.