]> git.mxchange.org Git - friendica.git/blob - library/perfect-scrollbar/README.md
Merge branch 'master' of ../save/merge/frio into frio_merge
[friendica.git] / library / perfect-scrollbar / README.md
1 # `perfect-scrollbar`
2
3 Minimalistic but perfect custom scrollbar plugin
4
5 [![Travis CI](https://travis-ci.org/noraesae/perfect-scrollbar.svg?branch=master)](https://travis-ci.org/noraesae/perfect-scrollbar)
6
7 If you want information of old versions<0.6.0, please refer to
8 [an old documentation](https://github.com/noraesae/perfect-scrollbar/tree/0.5.9).
9
10 ## Why perfect-scrollbar?
11
12 I was once working on a personal project, and trying to find the jQuery
13 scrollbar plugin that's *perfect*. But there was no *perfect* one.
14 That's why I decided to make one.
15
16 perfect-scrollbar is minimalistic but *perfect* (for me, and maybe for most developers)
17 scrollbar plugin working with jQuery or vanilla JavaScript as well.
18
19 I hope you love it!
20
21 ## [Demo](http://noraesae.github.com/perfect-scrollbar/)
22
23 [It's on the GitHub Pages](http://noraesae.github.com/perfect-scrollbar/).
24
25 ## What does *perfect* mean?
26
27 *perfect* means...
28
29 * There should be no css change on any original element.
30 * The scrollbar should not affect the original design layout.
31 * The design of the scrollbar should be (nearly) fully customizable.
32 * If the size of the container or the content changes, the scrollbar
33   size and position should be able to change.
34 * *New!* It should work with vanilla JavaScript and major tools like
35   NPM or Browserify.
36
37 ## Then perfect-scrollbar is really *perfect*?
38
39 * perfect-scrollbar has some requirements, but doesn't change or add
40   any style on original elements.
41 * perfect-scrollbar is designed not to have width or height. It's fixed
42   on the right and bottom side of the container.
43 * You can change nearly all css styles of the scrollbar. The scrollbar
44   design has no dependency on scripts.
45 * perfect-scrollbar supports an 'update' function. Whenever you need
46   to update the size or position of the scrollbar, just update.
47 * Additionally, perfect-scrollbar uses 'scrollTop' and 'scrollLeft',
48   not absolute positioning or something messy.
49 * perfect-scrollbar supports RTL perfectly on both WebKit and Gecko based browsers.
50
51 It's cool, isn't it?
52
53 ## Install
54
55 The best way to install and use perfect-scrollbar is with NPM.
56 It's registered on [npm](https://www.npmjs.org/package/perfect-scrollbar) as `perfect-scrollbar`.
57
58 ```
59 $ npm install perfect-scrollbar
60 ```
61
62 You can download the latest stable version with download links [here](http://noraesae.github.io/perfect-scrollbar/).
63 You also can find all releases on [Releases](https://github.com/noraesae/perfect-scrollbar/releases).
64
65 If you want to use the development version of the plugin, use the
66 source files which are not minified. They're in the `src` directory.
67 The development version may be unstable, but some known bugs may
68 have been fixed.
69
70 ```
71 $ git clone https://github.com/noraesae/perfect-scrollbar.git
72 $ cd perfect-scrollbar/src
73 $ npm install
74 $ gulp # will lint and build the source code.
75 ```
76
77
78 There is a Bower package for perfect-scrollbar as well. It is managed
79 under the [perfect-scrollbar-bower](https://github.com/noraesae/perfect-scrollbar-bower)
80 repository. The plugin is registered as `perfect-scrollbar`.
81
82 ```
83 $ bower install perfect-scrollbar
84 ```
85
86
87 You can also load it from [cdnjs](http://cdnjs.com/).
88 It is registered as [`jquery.perfect-scrollbar`](http://www.cdnjs.com/libraries/jquery.perfect-scrollbar).
89
90 ## Requirements
91
92 To make this plugin *perfect*, some requirements were unavoidable.
93 But, they're all very trivial and there is nothing to worry about.
94
95 The following requirements should meet.
96
97 * the container must have a 'position' css style.
98
99 The following requirements are included in the basic CSS, but please
100 keep in mind when you'd like to change the CSS files.
101
102 * the container must have an 'overflow:hidden' css style.
103 * the scrollbar's position must be 'absolute'.
104 * the scrollbar-x must have a 'bottom' css style, and the scrollbar-y
105   must have a 'right' css style.
106
107 ## How to use
108
109 First of all, please check if the container element meets the
110 requirements.
111
112 ```html
113 <link rel='stylesheet' href='dist/css/perfect-scrollbar.css' />
114 <style>
115   #container {
116     position: relative;
117     height: 100%; /* Or whatever you want (eg. 400px) */
118   }
119 </style>
120 ```
121
122 I would recommend using the plugin with NPM and CommonJS module system
123 like Browserify.
124
125 ```javascript
126 var Ps = require('perfect-scrollbar');
127 ```
128
129 Or you can just load the script file as usual.
130
131 ```html
132 <script src='dist/js/perfect-scrollbar.js'></script>
133 ```
134
135 To initialise the plugin, `Ps.initialize` is used.
136
137 ```javascript
138 var container = document.getElementById('container');
139 Ps.initialize(container);
140 ```
141
142 It can be initialised with optional parameters.
143
144 ```javascript
145 Ps.initialize(container, {
146   wheelSpeed: 2,
147   wheelPropagation: true,
148   minScrollbarLength: 20
149 });
150 ```
151
152 If the size of your container or content changes, call `update`.
153
154 ```javascript
155 Ps.update(container);
156 ```
157
158 If you want to destory the scrollbar, use `destroy`.
159
160 ```javascript
161 Ps.destroy(container);
162 ```
163
164 If you want to scroll to somewhere, just use a `scrollTop`
165 property and update.
166
167 ```javascript
168 container.scrollTop = 0;
169 Ps.update(container);
170 ```
171
172 You can also get information about how to use the plugin
173 from code in the `examples` directory of the source tree.
174
175 ## jQuery
176
177 As you may already know, perfect-scrollbar was a jQuery plugin.
178 And it *is* as well. There's a jQuery adaptor and the plugin can
179 be used in the same way it used to be used before.
180
181 I also recommend using NPM and CommonJS here, but it's not mandatory.
182
183 ```javascript
184 var $ = require('jquery');
185 require('perfect-scrollbar/jquery')($);
186 ```
187
188 For sure, you can just import a built script.
189
190 ```html
191 <script src='dist/js/perfect-scrollbar.jquery.js'></script>
192 ```
193
194 After importing it, you can use the plugin in the usual way.
195
196 ```javascript
197 $('#container').perfectScrollbar();          // Initialize
198 $('#container').perfectScrollbar({ ... });   // with options
199 $('#container').perfectScrollbar('update');  // Update
200 $('#container').perfectScrollbar('destroy'); // Destroy
201 ```
202
203 ## RequireJS  usage
204
205 For RequireJS loader, no need to write shim, simply import two libs:
206
207 ```javascript
208 require.config({
209   paths: {
210     perfectScrollbarJQuery: '.../perfect-scrollbar.jquery',
211     perfectScrollbar: '.../perfect-scrollbar',
212   }
213   ...
214 })
215 ```
216
217
218 and load `perfectScrollbar` in the initialiser of your app:
219
220 ```javascript
221 // for vanilla JS:
222 window.Ps = require('perfectScrollbar');
223
224 // for jQuery:
225 require('perfectScrollbarJQuery');
226 ```
227
228
229 ## AngularJS + RequireJS usage
230
231 With the require.config settings above, at the beginning of your app module
232 definition, you can have following code:
233
234 ```javascript
235 define([
236   'angular',
237   'perfectScrollbar',
238   'perfectScrollbarJquery'
239 ],
240 function (angular) {
241   var myApp = angular.module('myApp', [])
242   .run(function() {
243     window.Ps = require('perfectScrollbar');
244     require('perfectScrollbarJQuery');
245   })
246   return myApp;
247 });
248 ```
249
250 And initialise perfectScrollbar in a controller:
251
252 ```javascript
253 // by vanilla JS:
254 var container = document.getElementById('imgLoader');
255 Ps.initialize(container);
256 Ps.update(container);
257
258 // or by jQuery:
259 var imgLoader = $("#imgLoader")
260 imgLoader.perfectScrollbar();
261 ```
262
263 ## Optional parameters
264
265 perfect-scrollbar supports optional parameters.
266
267 ### wheelSpeed
268 The scroll speed applied to mousewheel event.  
269 **Default: 1**
270
271 ### wheelPropagation
272 If this option is true, when the scroll reaches the end of the side, mousewheel event will be propagated to parent element.  
273 **Default: false**
274
275 ### swipePropagation
276 If this option is true, when the scroll reaches the end of the side, touch scrolling will be propagated to parent element.  
277 **Default: true**
278
279 ### minScrollbarLength
280 When set to an integer value, the thumb part of the scrollbar will not shrink below that number of pixels.  
281 **Default: null**
282
283 ### maxScrollbarLength
284 When set to an integer value, the thumb part of the scrollbar will not expand over that number of pixels.  
285 **Default: null**
286
287 ### useBothWheelAxes
288 When set to true, and only one (vertical or horizontal) scrollbar is visible then both vertical and horizontal scrolling will affect the scrollbar.  
289 **Default: false**
290
291 ### useKeyboard
292 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.  
293 **Default: true**
294
295 ### suppressScrollX
296 When set to true, the scroll bar in X axis will not be available, regardless of the content width.  
297 **Default: false**
298
299 ### suppressScrollY
300 When set to true, the scroll bar in Y axis will not be available, regardless of the content height.  
301 **Default: false**
302
303 ### scrollXMarginOffset
304 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.  
305 **Default: 0**
306
307 ### scrollYMarginOffset
308 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.  
309 **Default: 0**
310
311 ### stopPropagationOnClick
312 When set to false, when clicking on a rail, the click event will be allowed to propagate.  
313 **Default: true**
314
315 ### useSelectionScroll
316 When set to true, you can scroll the container by selecting text and move the cursor.  
317 **Default: false**
318
319 ## Events
320
321 perfect-scrollbar dispatches custom events.
322
323 ### ps-scroll-y
324 This event fires when the y-axis is scrolled in either direction.
325
326 ### ps-scroll-x
327 This event fires when the x-axis is scrolled in either direction.
328
329 ### ps-scroll-up
330 This event fires when scrolling upwards.
331
332 ### ps-scroll-down
333 This event fires when scrolling downwards.
334
335 ### ps-scroll-left
336 This event fires when scrolling to the left.
337
338 ### ps-scroll-right
339 This event fires when scrolling to the right.
340
341 ### ps-y-reach-start
342 This event fires when scrolling reaches the start of the y-axis.
343
344 ### ps-y-reach-end
345 This event fires when scrolling reaches the end of the y-axis (useful for infinite scroll).
346
347 ### ps-x-reach-start
348 This event fires when scrolling reaches the start of the x-axis.
349
350 ### ps-x-reach-end
351 This event fires when scrolling reaches the end of the x-axis.
352
353 You can listen to these events either with vanilla JavaScript
354 ```javascript
355 document.addEventListener('ps-scroll-x', function () {
356   // ...
357 })
358 ```
359 or with jQuery
360 ```javascript
361 $(document).on('ps-scroll-x', function () {
362   // ...
363 })
364 ```
365
366 ## Contribution
367
368 #### Please read [Contributing](https://github.com/noraesae/perfect-scrollbar/wiki/Contributing) in the wiki before making any contribution.
369
370
371 I *really* welcome contributions! Please feel free to fork and issue pull requests when...
372
373 * You have a very nice idea to improve this plugin!
374 * You found a bug!
375 * You're good at English and can help my bad English!
376
377 For IE problems, please refer to [IE Support](https://github.com/noraesae/perfect-scrollbar#ie-support).
378
379 ## IE Support
380
381 The plugin would work in IEs >= IE9 (not well, though).
382
383 **The patches to fix problems in IE<=8 won't be accepted.**
384
385 When old IEs should be supported, please fork the project and
386 make patches personally.
387
388 ## Helpdesk
389
390 If you have any idea to improve this project or any problem
391 using this, please feel free to upload an
392 [issue](https://github.com/noraesae/perfect-scrollbar/issues).
393
394 For common problems there is a
395 [FAQ](https://github.com/noraesae/perfect-scrollbar/wiki/FAQ) wiki page. Please check the page before uploading an issue.
396
397 ## License
398
399 The MIT License (MIT) Copyright (c) 2015 Hyunje Alex Jun and other contributors.
400
401 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:
402
403 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
404
405 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.