]> git.mxchange.org Git - friendica.git/blob - library/perfect-scrollbar/README.md
Merge pull request #3788 from Alkarex/denmark_regions
[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 #### NPM
56
57 The best way to install and use perfect-scrollbar is with NPM.
58 It's registered on [npm](https://www.npmjs.com/package/perfect-scrollbar) as `perfect-scrollbar`.
59
60 ```
61 $ npm install perfect-scrollbar
62 ```
63
64 #### Rails
65
66 In the case you would like to have perfect-scrollbar in your Rails application, there is the [perfect-scrollbar-rails gem](https://github.com/YourCursus/perfect-scrollbar-rails).
67
68 #### Manually
69
70 You can download the latest stable version with download links [here](http://noraesae.github.io/perfect-scrollbar/).
71 You also can find all releases on [Releases](https://github.com/noraesae/perfect-scrollbar/releases).
72
73 #### From sources
74
75 If you want to use the development version of the plugin, use the
76 source files which are not minified. They're in the `src` directory.
77 The development version may be unstable, but some known bugs may
78 have been fixed.
79
80 ```
81 $ git clone https://github.com/noraesae/perfect-scrollbar.git
82 $ cd perfect-scrollbar/src
83 $ npm install
84 $ gulp # will lint and build the source code.
85 ```
86
87 #### Bower
88
89 There is a Bower package for perfect-scrollbar as well. It is managed
90 under the [perfect-scrollbar-bower](https://github.com/noraesae/perfect-scrollbar-bower)
91 repository. The plugin is registered as `perfect-scrollbar`.
92
93 ```
94 $ bower install perfect-scrollbar
95 ```
96
97 #### CDNs
98
99 * [cdnjs](http://www.cdnjs.com/libraries/jquery.perfect-scrollbar)
100 * [JSDelivr](https://www.jsdelivr.com/projects/perfect-scrollbar)
101
102 #### JSFiddle
103
104 You can fork the following JSFiddles for testing and experimenting purposes:
105
106 * [Perfect Scrollbar](https://jsfiddle.net/DanielApt/xv0rrxv3/)
107 * [Perfect Scrollbar (jQuery)](https://jsfiddle.net/DanielApt/gbfLazpx/)
108
109 ## Before using perfect-scrollbar
110
111 The following requirements should meet.
112
113 * the container must have a 'position' css style.
114 * the container must be a normal container element.
115   * PS may not work well in `body`, `textarea`, `iframe` or flexbox.
116
117 The following requirements are included in the basic CSS, but please
118 keep in mind when you'd like to change the CSS files.
119
120 * the container must have an 'overflow: hidden' css style.
121 * the scrollbar's position must be 'absolute'.
122 * the scrollbar-x must have a 'bottom' css style, and the scrollbar-y
123   must have a 'right' css style.
124   
125 Please keep in mind that perfect-scrollbar won't completely emulate native
126 scrolls. Scroll hooking is generally considered as bad practice, and
127 perfect-scrollbar should be used with care. Unless custom scroll is really needed,
128 please consider using native scrolls.
129
130 ## How to use
131
132 First of all, please check if the container element meets the
133 requirements.
134
135 ```html
136 <link rel='stylesheet' href='dist/css/perfect-scrollbar.css' />
137 <style>
138   #container {
139     position: relative;
140     height: 100%; /* Or whatever you want (eg. 400px) */
141   }
142 </style>
143 ```
144
145 I would recommend using the plugin with NPM and CommonJS module system
146 like Browserify.
147
148 ```javascript
149 var Ps = require('perfect-scrollbar');
150 ```
151
152 Or you can just load the script file as usual.
153
154 ```html
155 <script src='dist/js/perfect-scrollbar.js'></script>
156 ```
157
158 To initialise the plugin, `Ps.initialize` is used.
159
160 ```javascript
161 var container = document.getElementById('container');
162 Ps.initialize(container);
163 ```
164
165 It can be initialised with optional parameters.
166
167 ```javascript
168 Ps.initialize(container, {
169   wheelSpeed: 2,
170   wheelPropagation: true,
171   minScrollbarLength: 20
172 });
173 ```
174
175 If the size of your container or content changes, call `update`.
176
177 ```javascript
178 Ps.update(container);
179 ```
180
181 If you want to destroy the scrollbar, use `destroy`.
182
183 ```javascript
184 Ps.destroy(container);
185 ```
186
187 If you want to scroll to somewhere, just use a `scrollTop`
188 property and update.
189
190 ```javascript
191 container.scrollTop = 0;
192 Ps.update(container);
193 ```
194
195 You can also get information about how to use the plugin
196 from code in the `examples` directory of the source tree.
197
198 ## jQuery
199
200 As you may already know, perfect-scrollbar was a jQuery plugin.
201 And it *is* as well. There's a jQuery adaptor and the plugin can
202 be used in the same way it used to be used before.
203
204 I also recommend using NPM and CommonJS here, but it's not mandatory.
205
206 ```javascript
207 var $ = require('jquery');
208 require('perfect-scrollbar/jquery')($);
209 ```
210
211 For sure, you can just import a built script.
212
213 ```html
214 <script src='dist/js/perfect-scrollbar.jquery.js'></script>
215 ```
216
217 After importing it, you can use the plugin in the usual way.
218
219 ```javascript
220 $('#container').perfectScrollbar();          // Initialize
221 $('#container').perfectScrollbar({ ... });   // with options
222 $('#container').perfectScrollbar('update');  // Update
223 $('#container').perfectScrollbar('destroy'); // Destroy
224 ```
225
226 ## RequireJS  usage
227
228 For RequireJS loader, no need to write shim, simply import two libs:
229
230 ```javascript
231 require.config({
232   paths: {
233     perfectScrollbarJQuery: '.../perfect-scrollbar.jquery',
234     perfectScrollbar: '.../perfect-scrollbar',
235   }
236   ...
237 })
238 ```
239
240
241 and load `perfectScrollbar` in the initialiser of your app:
242
243 ```javascript
244 // for vanilla JS:
245 window.Ps = require('perfectScrollbar');
246
247 // for jQuery:
248 require('perfectScrollbarJQuery');
249 ```
250
251
252 ## AngularJS + RequireJS usage
253
254 With the require.config settings above, at the beginning of your app module
255 definition, you can have following code:
256
257 ```javascript
258 define([
259   'angular',
260   'perfectScrollbar',
261   'perfectScrollbarJquery'
262 ],
263 function (angular) {
264   var app = angular.module('myApp', []);
265   app.run(function () {
266     window.Ps = require('perfectScrollbar');
267     require('perfectScrollbarJQuery');
268   });
269   return app;
270 });
271 ```
272
273 And initialise perfectScrollbar in a controller:
274
275 ```javascript
276 // by vanilla JS:
277 var container = document.getElementById('imgLoader');
278 Ps.initialize(container);
279 Ps.update(container);
280
281 // or by jQuery:
282 var imgLoader = $('#imgLoader')
283 imgLoader.perfectScrollbar();
284 ```
285
286 ## Optional parameters
287
288 perfect-scrollbar supports optional parameters.
289
290 ### handlers
291 It is a list of handlers to use to scroll the element.  
292 **Default**: `['click-rail', 'drag-scrollbar', 'keyboard', 'wheel', 'touch']`  
293 **Disabled by default**: `'selection'`
294
295 ### wheelSpeed
296 The scroll speed applied to mousewheel event.  
297 **Default**: `1`
298
299 ### wheelPropagation
300 If this option is true, when the scroll reaches the end of the side, mousewheel event will be propagated to parent element.  
301 **Default**: `false`
302
303 ### swipePropagation
304 If this option is true, when the scroll reaches the end of the side, touch scrolling will be propagated to parent element.  
305 **Default**: `true`
306
307 ### minScrollbarLength
308 When set to an integer value, the thumb part of the scrollbar will not shrink below that number of pixels.  
309 **Default**: `null`
310
311 ### maxScrollbarLength
312 When set to an integer value, the thumb part of the scrollbar will not expand over that number of pixels.  
313 **Default**: `null`
314
315 ### useBothWheelAxes
316 When set to true, and only one (vertical or horizontal) scrollbar is visible then both vertical and horizontal scrolling will affect the scrollbar.  
317 **Default**: `false`
318
319 ### suppressScrollX
320 When set to true, the scroll bar in X axis will not be available, regardless of the content width.  
321 **Default**: `false`
322
323 ### suppressScrollY
324 When set to true, the scroll bar in Y axis will not be available, regardless of the content height.  
325 **Default**: `false`
326
327 ### scrollXMarginOffset
328 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.  
329 **Default**: `0`
330
331 ### scrollYMarginOffset
332 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.  
333 **Default**: `0`
334
335 ### theme
336 A string. It's a class name added to the container element. The class name is prepended with `ps-theme-`. So default theme class name is `ps-theme-default`. In order to create custom themes with scss use `ps-container($theme)` mixin, where `$theme` is a scss map.  
337 **Default**: `'default'`
338
339 **Example 1:**
340
341 Add `theme` parameter:
342 ```javascript
343 Ps.initialize(container, {
344   theme: 'my-theme-name'
345 });
346 ```
347 Create a class name prefixed with `.ps-theme-`. Include `ps-container()` mixin. It's recommended to use `map-merge()` to extend `$ps-theme-default` map with your custom styles.
348 ```scss
349 .ps-theme-my-theme-name {
350   @include ps-container(map-merge($ps-theme-default, (
351     border-radius: 0,
352     scrollbar-x-rail-height: 20px,
353     scrollbar-x-height: 20px,
354     scrollbar-y-rail-width: 20px,
355     scrollbar-y-width: 20px
356   )));
357 }
358 ```
359
360 **Example 2:**
361
362 Alternatively, if you don't want to create your own themes, but only modify the default one, you could simply overwrite `$ps-*` variables with your own values. In this case `theme` parameter is not required when calling `.initialize()` method. Remember do define your own variables before the `theme.scss` file is imported.
363
364
365 ## Events
366
367 perfect-scrollbar dispatches custom events.
368
369 ### ps-scroll-y
370 This event fires when the y-axis is scrolled in either direction.
371
372 ### ps-scroll-x
373 This event fires when the x-axis is scrolled in either direction.
374
375 ### ps-scroll-up
376 This event fires when scrolling upwards.
377
378 ### ps-scroll-down
379 This event fires when scrolling downwards.
380
381 ### ps-scroll-left
382 This event fires when scrolling to the left.
383
384 ### ps-scroll-right
385 This event fires when scrolling to the right.
386
387 ### ps-y-reach-start
388 This event fires when scrolling reaches the start of the y-axis.
389
390 ### ps-y-reach-end
391 This event fires when scrolling reaches the end of the y-axis (useful for infinite scroll).
392
393 ### ps-x-reach-start
394 This event fires when scrolling reaches the start of the x-axis.
395
396 ### ps-x-reach-end
397 This event fires when scrolling reaches the end of the x-axis.
398
399 You can listen to these events either with vanilla JavaScript
400 ```javascript
401 document.addEventListener('ps-scroll-x', function () {
402   // ...
403 })
404 ```
405 or with jQuery
406 ```javascript
407 $(document).on('ps-scroll-x', function () {
408   // ...
409 })
410 ```
411
412 ## Tips
413
414 ### Scrolling children inside perfect-scrollbar
415
416 You can natively scroll children inside `perfect-scrollbar` with the mouse-wheel. Scrolling automatically works if 
417 the child is a `textarea`. All other elements need to have the `ps-child` class. This is demonstrated in [`/examples/children-native-scroll.html`](examples/children-native-scroll.html)
418
419 ## IE Support
420
421 The plugin is designed to work in modern browsers, including the very latest
422 version of IE and Edge. Specifically, it should work in IEs >= IE10. If there
423 is any issue in the browsers, please [file it](https://github.com/noraesae/perfect-scrollbar/issues).
424
425 **The patches to fix problems in IE<=9 won't be accepted.**
426
427 When old IEs should be supported, please fork the project and
428 make patches personally.
429
430 ## Helpdesk
431
432 If you have any idea to improve this project or any problem
433 using this, please feel free to upload an
434 [issue](https://github.com/noraesae/perfect-scrollbar/issues).
435
436 For common problems there is a
437 [FAQ](https://github.com/noraesae/perfect-scrollbar/wiki/FAQ) wiki page. Please check the page before uploading an issue.
438
439 ## License
440
441 The MIT License (MIT) Copyright (c) 2016 Hyunje Alex Jun and other contributors.
442
443 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:
444
445 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
446
447 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.