scrollbar.html
11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
<section>
<h1 class="blue" data-id="#custom/scrollbar"><i class="ace-icon fa fa-desktop grey"></i> Scrollbars</h1>
<div class="hr hr-double hr32"></div>
<!-- #section:custom/scrollbar -->
<div class="help-content">
<h3 class="info-title smaller">1. Scrollbars</h3>
<div class="info-section">
<ul class="info-list list-unstyled">
<li>
Trying different scrollbar plugins,
I wasn't able to find a lightweight and easy to use one,
which is also touch friendly.
<br />
So I thought it's better to make one.
<br />
It's minimal but should be enough for most cases.
<br />
You can also use other more advanced plugins if necessary. There should be no conflicts.
</li>
<li>
Here is a simple snippet which add vertical scrollbars to an element and limits its size to 400:
<pre data-language="javascript">
$('#my-content').ace_scroll({size: 400});
</pre>
</li>
</ul>
</div>
<h3 class="info-title smaller">2. Options</h3>
<div class="info-section">
<ul class="info-list list-unstyled">
<li>
<code>size</code> which is 200px by default
<pre data-language="javascript">
$('#my-content').ace_scroll({size: 400});
</pre>
You can also specify size using <code>data-size</code> attribute:
<pre data-language="html">
<div id="my-content" data-size="300">
...
</div>
</pre>
</li>
<li>
<code>horizontal</code> default=false. If true, horizontal scrollbars will be added
<pre data-language="javascript">
$('#my-content').ace_scroll({horizontal: true});
</pre>
</li>
<li><code>mouseWheel</code> default=true. Scrolls content on mouse wheel event. When end of content is reached, mouse wheel event will be propagated to window</li>
<li>
<code>mouseWheelLock</code> default=false. If true and we have reached end of scrolling on our element, mouse wheel event won't be propagated to window
<br />
<code>lockAnyway</code> default=false. If true, even if scrollbars are not needed and are not visible yet, mouse wheel event won't be propagated to window
<br />
<pre data-language="javascript">
$('#my-content').ace_scroll({size: 300, mouseWheelLock: true});
</pre>
</li>
<li><code>styleClass</code> additional style classes you can add to scrollbars. See next section for more info.</li>
<li>
<code>hoverReset</code> default=true, because of window size changes and other document layout changes,
content sizes may change and we may need to reset scrollbar size.
<br />
It can be done on mouseenter event, which is set to true by default.
</li>
<li>
<code>reset</code> default=false. If true, content will be scrolled to 0, on initialization.
<br />
Does not work when the element is hidden at first.
</li>
<li>
<code>dragEvent</code> default=false. If true an event will be triggered when
user starts dragging scrollbars using mouse.
</li>
<li>
<code>scrollEvent</code> default=false. If true an event will be triggered when
content is scrolled.
</li>
<li>
<code>touchDrag</code> default=true, which adds touch drag event for touch devices.
</li>
<li>
<code>hideOnIdle</code> will hide scrollbars when user is not scrolling content
<br />
You may also want to use <code>hideDelay</code> which specifies time before hiding scrollbars
and also <code>observeContent</code> which specifies whether content and scrollbar size
should be reset before making it visible:
<pre data-language="javascript">
$('#my-content').ace_scroll({
//other options
hideOnIdle: true,
hideDelay: 1500,
observeContent: true
});
</pre>
</li>
<!--
<li>
<code>touchSwipe</code> default=false, which adds touch swipe event instead of drag event.
</li>
-->
</ul>
</div>
<h3 class="info-title smaller">3. Styles</h3>
<div class="info-section">
<ul class="info-list list-unstyled">
<li>
Some additional classes you can add using <code>styleClass</code> option:
<ol>
<li><code>scroll-margin</code> which add 1px space between content and scrollbars</li>
<li><code>scroll-left</code> shows scrollbars on left instead of right</li>
<li><code>scroll-top</code> shows horizontal scrollbars on top instead of bottom</li>
<li><code>scroll-dark</code> darker scrollbars</li>
<li><code>scroll-light</code> lighter scrollbars</li>
<li><code>no-track</code> hides scroll track</li>
<li><code>scroll-visible</code> scrollbars always visible</li>
<li><code>scroll-thin</code> thinner scrollbars</li>
<li><code>scroll-chrome</code> similar to latest version of Google Chrome scrollbars </li>
</ol>
</li>
<li>
<pre data-language="javascript">
$('#my-content').ace_scroll({
size: 300,
styleClass: 'scroll-dark scroll-left scroll-thin'
});
</pre>
</li>
</ul>
</div>
<h3 class="info-title smaller">4. Events</h3>
<div class="info-section">
<ul class="info-list list-unstyled">
<li>
If you set <code>scrollEvent</code> to true, a scroll event will be triggered when element is scrolled:
<pre data-language="javascript">
$('#my-content')
.ace_scroll({
scrollEvent: true
})
.on('scroll', function() {
//element scrolled
});
</pre>
But it's better to listen to the inner content's native scroll event:
<pre data-language="javascript">
$('#my-content').find('.scroll-content').on('scroll', function() {
//element scrolled
});
</pre>
</li>
<li>
If you set <code>dragEvent</code> to true, some drag events will be triggered when scrollbars are dragged:
<pre data-language="javascript">
$('#my-content')
.ace_scroll({
dragEvents: true
})
.on('drag.start', function() {
//started dragging
})
.on('drag._end', function() {
//ended dragging
})
</pre>
</li>
</ul>
</div>
<h3 class="info-title smaller" data-id="#custom/scrollbar.touch-drag">5. Touch Drag Event</h3>
<!-- #section:custom/scrollbar.touch-drag -->
<div class="info-section">
<ul class="info-list list-unstyled">
<li>
There is also a custom touch drag event specifically for use on scrollbars.
<br />
You can use it with other elements as well, though I recommend a more advanced library such as
<b>Hammer.js</b>
</li>
<li>
You can use it like this:
<pre data-language="javascript">
$('#some-element').on('ace_drag', function(event) {
//var dir = event.direction;// up down left right
//var distanceX = event.dx
//var distanceY = event.dy
})
</pre>
</li>
</ul>
</div>
<!-- /custom/scrollbar.touch-drag -->
<h3 class="info-title smaller">6. Functions</h3>
<div class="info-section">
<ul class="info-list list-unstyled">
<li>
The following functions are available for scroller plugin:
<ol>
<li><code>reset</code> resets scrollbar size</li>
<li><code>disable</code> disables scrollbars</li>
<li><code>enable</code> enables scrollbars</li>
<li><code>end</code> scroll to end</li>
<li><code>start</code> scroll to start</li>
<!--
<li><code>destroy</code> destroys scrollbars</li>
-->
<li><code>update</code> updates an option (currently only size, style and mousewheel options)</li>
<!--
<li><code>modify</code> updates options and recreates scrollbars</li>
-->
</ol>
</li>
<li>
<pre data-language="javascript">
$('#my-content').ace_scroll('reset');
$('#my-content').ace_scroll('disable');
$('#my-content').ace_scroll('update', {size: 250});
$('#my-content').ace_scroll('modify', completely_new_options);
</pre>
</li>
</ul>
</div>
<h3 class="info-title smaller" data-id="#custom/scrollbar.horizontal">7. Horizontal</h3>
<!-- #section:custom/scrollbar.horizontal -->
<div class="info-section">
<ul class="info-list list-unstyled">
<li>
Horizontal scrollbars can be created by specifying <code>horizontal</code> option:
<pre data-language="javascript">
$('#my-content').ace_scroll({
horizontal: true,
size: 600,
styleClass: 'scroll-top',
mouseWheelLock: true
});
</pre>
</li>
<li>
Sometimes you may need to add some padding to the element if scrollbars appear above content:
<pre data-language="javascript">
$('#my-content').ace_scroll({
horizontal: true,
//options here
}).css('padding-top', 15);
</pre>
</li>
<li>
If you are using RTL (right to left) direction,
please note that horizontal scrolling is inconsistent between browsers.
<br />
So it's better to change scrollbars to LTR and make the content RTL again.
<br />
You can use <code>.make-ltr</code> and <code>.make-rtl</code> classes:
<br />
<pre data-language="javascript">
$('#my-content').addClass('make-ltr')
.find('.scroll-content').wrapInner('<div class="make-rtl" />');
</pre>
</li>
Or statically inside your HTML:
<pre data-language="html">
<div id="my-content" class="make-ltr">
<div class="make-rtl">
...
</div>
</div>
</pre>
<pre data-language="javascript">
$('#my-content').ace_scroll({
horizontal: true,
//other options here
})
</pre>
</li>
</ul>
</div>
<!-- /section:custom/scrollbar.horizontal -->
<h3 class="info-title smaller" data-id="#custom/scrollbar.sidebar">8. Sidebar Scrollbars</h3>
<!-- #section:custom/scrollbar.sidebar -->
<div class="info-section">
<ul class="info-list list-unstyled">
<li>
You can also use scrollbar for sidebar whether it's fixed or not.
</li>
<li>
I have used two approaches for sidebar
</li>
<li>
The first one which is used by default, does not use <code>overflow:hidden</code> and
can be used only on fixed sidebar.
<br />
The advantage is that .hover submenus or mininized sidebar can also have scrollbars and
submenus will be shown outside of sidebar area without problem.
</li>
</li>
Second one uses real scrollbars and has <code>overflow:hidden</code> applied to it.
<br />
It can be used on both normal and fixed sidebar.
<br />
To enable it you should <a href="../build/js.html">build a custom JS</a> using 2nd sidebar scrollbar style.
</li>
<li>
Each one has several options which you can edit inside:
<ol>
<li><code>assets/js/ace/ace.js</code></li>
<li><code>assets/js/ace.js</code></li>
<li><code>dist/js/ace.min.js</code></li>
</ol>
<br />
Look for <code>sidebar_scrollable</code> and change options as needed.
</li>
<li>
Options for first style (fixed sidebar only):
<ol>
<li><code>scroll_to_active</code> If true, sidebar will be scrolled down to show active menu item on page load</li>
<li><code>include_shortcuts</code> If true, shortcuts will also be inside scroll area. Otherwise it will be above scroll area</li>
<li><code>include_toggle</code> If true, sidebar toggle(minimize button) will also be inside scroll area. Otherwise it will be below scroll area</li>
<li><code>smooth_scroll</code> If true, sidebar scrolling will be smooth using CSS3 transition</li>
<li><code>outside</code> If true, scrollbar will be outside of scroll area</li>
</ol>
</li>
<li>
Options for secod style (normal/fixed sidebar):
<ol>
<li><code>only_fixed</code> If true, scrollbars will be enabled for fixed sidebar only</li>
<li><code>scroll_to_active</code> If true, sidebar will be scrolled down to show active menu item on page load</li>
<li><code>include_shortcuts</code> If true, shortcuts will also be inside scroll area. Otherwise it will be above scroll area</li>
<li><code>include_toggle</code> If true, sidebar toggle(minimize button) will also be inside scroll area. Otherwise it will be below scroll area</li>
</ol>
</li>
</ul>
</div>
<!-- /section:custom/scrollbar.sidebar -->
</div>
<!-- /section:custom/scrollbar -->
</section>