|
2 | 2 |
|
3 | 3 | ## The Crux of the Matter
|
4 | 4 |
|
5 |
| -The general purpose of the plugin is to provide some lengthy containers on the page with a separate horizontal scroll bar, which does not vanish from sight when the entire page is scrolled. So, the user will always be able to scroll the container even if its own scroll bar is hidden from view. |
| 5 | +The general purpose of the plugin is to provide some lengthy containers on the page with a separate horizontal scroll bar, which does not vanish from sight when the entire page is scrolled. So, the user will always be able to scroll the container even if its own scroll bar is outside the viewport. |
6 | 6 |
|
7 |
| -Moreover, the plugin displays such an additional floating scroll bar only in case of actual need, i.e. the floatingScroll does not result in unnecessary scroll bar duplication. So, one uses the floating scroll bar only if the “native” one is out of sight. |
| 7 | +Moreover, the plugin displays such an additional floating scroll bar only in case of actual need, i.e. floatingScroll does not result in unnecessary scroll bar duplication. So, one uses the floating scroll bar only if the “native” one is out of sight. |
8 | 8 |
|
9 | 9 | ## Details & API
|
10 | 10 |
|
11 |
| -There is the only public method used to instantiate and control a floating scroll — `.floatingScroll()` (note that the old method alias `attachScroll` is kept for backward compatibility, but it will be removed in future versions). The plugin method `.floatingScroll()` should be called in context of a scrollable container. It takes an optional argument `method`. The currently supported methods are |
| 11 | +There is the only public method used to instantiate and control a floating scroll — `.floatingScroll()`. The plugin method `.floatingScroll()` should be called in context of a scrollable container. It takes an optional argument `method`. The currently supported methods are |
12 | 12 |
|
13 | 13 | * `init` (default value) — used to initialize a floating scroll widget;
|
14 | 14 | * `update` — used to force update of the floating scroll bar parameters (size and position);
|
15 | 15 | * `destroy` — removes a scroll bar and all related event handlers.
|
16 | 16 |
|
17 |
| -You may also trigger events `update.fscroll` and `destroy.fscroll` for containers with attached floating scroll bar: this does the same as invoking the corresponding methods. |
| 17 | +You may also [trigger](https://api.jquery.com/trigger/) events `update.fscroll` and `destroy.fscroll` on containers with attached floating scroll bar: this does the same as invoking the corresponding methods. |
18 | 18 |
|
19 | 19 | ## Usage
|
20 | 20 |
|
21 | 21 | ### Inclusion of plugin files
|
22 | 22 |
|
23 |
| -The plugin requires the CSS file [jquery.floatingscroll.css](src/jquery.floatingscroll.css) to be included on the page (you may also import it in your CSS/LESS files). The plugin's script file [jquery.floatingscroll.min.js](src/jquery.floatingscroll.min.js) may be added on the web page either via a separate `<script>` element or it may be loaded by any AMD/CommonJS compatible module loader. This is a jQuery plugin so be sure that this library is added and accessible. |
| 23 | +The plugin requires the CSS file [jquery.floatingscroll.css](dist/jquery.floatingscroll.css) to be included on the page (you may also import it in your CSS/LESS files). The plugin’s script file [jquery.floatingscroll.min.js](dist/jquery.floatingscroll.min.js) may be added on the web page either via a separate `<script>` element, or it may be loaded by any AMD/CommonJS compatible module loader. This is a jQuery plugin so be sure that this library is added and accessible. |
| 24 | + |
| 25 | +:bulb: **Tip:** If you don’t care about supporting old browsers, feel free to use the file [jquery.floatingscroll.es6.min.js](dist/jquery.floatingscroll.es6.min.js), which is de facto the same as jquery.floatingscroll.min.js but is written in ES6, and is a bit smaller. |
24 | 26 |
|
25 | 27 | ### Initialisation
|
26 | 28 |
|
27 |
| -The only thing required to apply the floatingScroll to a static container (whose sizes will never change during the session) is a single call of the `.floatingScroll()` method on the DOM ready event: |
| 29 | +The only thing required to apply floatingScroll to a static container (whose sizes will never change during the session) is a single call of the `.floatingScroll()` method on the DOM ready event: |
28 | 30 |
|
29 | 31 | ```javascript
|
30 | 32 | $(document).ready(function () {
|
31 | 33 | $(".spacious-container").floatingScroll();
|
32 | 34 | });
|
33 | 35 | ```
|
34 | 36 |
|
| 37 | +### Auto-initialisation |
| 38 | + |
| 39 | +There is another way of initialising the floatingScroll widget without writing a single line of JavaScript code. Just add an attribute `data-fl-scrolls` to the desired container. As the DOM is ready the plugin will detect all such elements and will do initialisation automatically. |
| 40 | + |
| 41 | +```html |
| 42 | +<div class="spacious-container" data-fl-scrolls> |
| 43 | + <!-- Horizontally wide contents --> |
| 44 | +</div> |
| 45 | +``` |
| 46 | + |
| 47 | +_The auto-initialisation feature is available starting with v3.0.0._ |
| 48 | + |
35 | 49 | ### Updating scroll bar
|
36 | 50 |
|
37 | 51 | If you attach a floating scroll bar to a container whose size and/or content may dynamically change, then you need a way to update the scroll bar each time the container changes. This can be done by invoking the method `update` as in example below.
|
@@ -72,16 +86,12 @@ The `.fl-scrolls-viewport` element (1) is a positioned block (with any type of p
|
72 | 86 | $(".spacious-container").floatingScroll();
|
73 | 87 | ```
|
74 | 88 |
|
75 |
| -The plugin's CSS provides some basic styles for elements with classes `.fl-scrolls-viewport` and `.fl-scrolls-body`. Feel free to adjust their styles in your stylesheets as needed. |
| 89 | +The plugin’s CSS file provides some basic styles for elements with classes `.fl-scrolls-viewport` and `.fl-scrolls-body`. Feel free to adjust their styles in your stylesheets as needed. |
76 | 90 |
|
77 | 91 | ### Tips
|
78 | 92 |
|
79 | 93 | You can also make a floating scroll bar more “unobtrusive” so that it will appear only when the mouse pointer hovers over the scrollable container. To do so just apply the class `fl-scrolls-hoverable` to the desired scrollable container owning the floating scroll bar.
|
80 | 94 |
|
81 | 95 | ## Live demos
|
82 | 96 |
|
83 |
| -You may find some demos of use the floatingScroll plugin [here](https://amphiluke.github.io/floating-scroll/). |
84 |
| - |
85 |
| -## Previous versions |
86 |
| - |
87 |
| -Prior to v2.2.0, the plugin was the part of the [jquery-plugins](https://github.com/Amphiluke/jquery-plugins) repo. If for some purpose you want to get commit history for older plugin versions, you can [extract](https://github.com/Amphiluke/jquery-plugins/commits/master/src/floatingscroll) it from that “old” repo. |
| 97 | +Check out some usage demos [here](https://amphiluke.github.io/floating-scroll/). |
0 commit comments