-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlider.html
389 lines (352 loc) · 16.4 KB
/
Slider.html
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
385
386
387
388
389
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css"
integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<link rel="stylesheet" href="dist/css/SourcePage.css" />
<link rel="stylesheet" href="dist/css/A11yWrapper.css" />
<title>Accessible and Responsive slider</title>
</head>
<body>
<div class="jumbotron">
<div class="container">
<h1 class="display-3">Slider</h1>
<p>
This slider is purely built on JavaScript and fully customizable. Developer needs to
call the wrapper class and show container where slider will be created on the fly.
</p>
</div>
</div>
<div class="container" role="main">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="index.html">Home</a></li>
<li class="breadcrumb-item active" aria-current="page">Slider</li>
</ol>
</nav>
<div class="row mt-4">
<nav class="col-md-3 d-none d-md-block bg-light sidebar">
<div class="sidebar-sticky">
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link active" href="#init">Initial setup</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="#configuration">Configuration</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="#multiple">Multiple use</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="#accessibility">Accessibility</a>
</li>
</ul>
</div>
</nav>
<div class="col-sm-12 col-md-9">
<h2>Demo</h2>
<div id="idSliders1" class='slider-container'></div>
<div id="sliderVal" class="value mt-2">0</div>
<div id="init" class="mt-5">
<h2>Initial setup</h2>
<p>
Paste below HTML structure at your code where you want Slider to appear. Any ID or classname is
fine.
Call the slider component from Wrapper library and Slider
</p>
<pre>
<code>
<span>
<div id="sliderID" class='slider-class'></div>
</span>
</code>
</pre>
<p>
Call the slider component from Wrapper library at initial Load event. It can be
<strong>$(document).ready(...)</strong> or <strong>Window.onload</strong> or
<strong>Window.eventListener('load', ...)</strong>. Then slider will
load with default settings.
</p>
</div>
<div id="configuration">
<h2>Configuration</h2>
<p>
All sort of customization need to be passed as an Object.
Slider settings can be customized by altering few attributes like
</p>
<div class="table-responsive">
<table class="table table-bordered">
<thead class="thead-inverse">
<tr>
<th>Key name</th>
<th>Type</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>id</td>
<td>String</td>
<td>It's a required attribute and necessary to follow accessibility
guideline. This should be unique and </td>
</tr>
<tr>
<td>min</td>
<td>Integer. No fraction allowed</td>
<td>Determine minimum value to start with. Default is O</td>
</tr>
<tr>
<td>max</td>
<td>Integer. No fraction allowed</td>
<td>Determine the maximum value Slider will hold. Default is 100</td>
</tr>
<tr>
<td>now</td>
<td>Integer. No fraction allowed</td>
<td>Set initial value in Slider. Default is 0</td>
</tr>
<tr>
<td>stepper</td>
<td>Integer. No fraction allowed</td>
<td>Set the jump count of Slider. This is necessary for PAGE UP and PAGE DOWN keys.
For an example - If stepped is set to 10 then pressing PAGE UP will increment slider value by 10.
Default is 10</td>
</tr>
<tr>
<td>label</td>
<td>String</td>
<td>Label stating purpose of Slider. This is a required key. Passing empty string
will display default string from Library which is 'Slider'
</td>
</tr>
<tr>
<td>output</td>
<td>String</td>
<td>Pass the reference (ID or Class) of a container where result would display when
slider
moves</td>
</tr>
<tr>
<td>onSliderChange</td>
<td>Function</td>
<td>This is a callback function and triggers whenever Slider moves. It always returns
Slider
value
after movement.
</td>
</tr>
<tr>
<td>css</td>
<td>Object</td>
<td>It's an optional key and holds color settings for Slider. Any valid color code format is supported.
All the keys inside the object are optional too.
<ul>
<li>
<strong>thumbColor</strong> - Set color to circular thumb. Default is #0fa683
</li>
<li>
<strong>borderColor</strong> - Set border color outer to slider rail. Default is #d7d0d0
</li>
<li>
<strong>fillColor</strong> - Set filled color in slider rail to visually show how much it moved to right. Default is #5abfa8
</li>
<li>
<strong>backgroundColor</strong> - Set background color to rail. It visually shows empty rail and how much left to be filled. Default is #f3f0f0
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</div>
<pre>
<code>
<span>
var sliderOption = {
min: 0,
max: 255,
now: 50,
stepper: 10,
css:{
thumbColor: '#6e6d6d',
borderColor: '#d7d0d0',
fillColor: '#a4a1a1',
backgroundColor: '#f3f0f0'
},
label: 'Demo slider',
output: '#sliderVal',
onSliderChange: function (data) {
console.log('Selected Item: ', data);
}
};
window.addEventListener('load', function () {
window.A11yWrapper('.slider-class').slider(sliderOption);
});
</span>
</code>
</pre>
</div>
<div id="multiple">
<h2>How to use Slider component multiple times</h2>
<div class="mt-2 mb-1">
<div class='multi-slider-container'></div>
<div id="sliderValMulti1" class="value mt-2">0</div>
</div>
<div class="mb-1">
<div class='multi-slider-container'></div>
<div id="sliderValMulti2" class="value mt-2">0</div>
</div>
<p>
Slider can be positioned in multiple places while initiating the library. Also, multiple slider
can have different configurations as well. Below two ways, Slider can be called several times.
</p>
<ul>
<li>
<strong>Using multiple ID.</strong>
<p class="mt-3">
Call wrapper class multiple times for each distinctive ID.
</p>
<pre>
<code>
<span>
var sliderOption1 = {...},
sliderOption2 = {...},
window.addEventListener('load', function () {
window.A11yWrapper('#id_1').slider(sliderOption1);
window.A11yWrapper('#id_2').slider(sliderOption2);
});
</span>
</code>
</pre>
</li>
<li>
<strong>Using same class for multiple elements.</strong>
<p class="mt-3">
In below example, configuration object will be assigned sequentially. First object
will be assigned to first Slider and second object will be assigned to second Slider.
If only one configuration object is passed then both Slider will be built upon that single
configuration object.
</p>
<pre>
<code>
<span>
var sliderOption1 = {...},
sliderOption2 = {...},
window.addEventListener('load', function () {
window.A11yWrapper('.slider-class').slider(sliderOption1, sliderOption2);
});
</span>
</code>
</pre>
</li>
</ul>
</div>
<div id="accessibility">
<h2>Accessibility</h2>
<p class="lead mt-3">Keyboard interaction</p>
<ul>
<li>
<strong>HOME/ END</strong> - HOME key press move Slider to initial position. END key press move slider to max position
</li>
<li>
<strong>PAGE UP/ DOWN</strong> - PAGE UP or PAGE DOWN key press jump slider by the position. It can be either 10 or 15 etc.
</li>
<li>
<strong>RIGHT/ LEFT/ UP/ DOWN</strong> - RIGHT and UP arrow key increase Slider value. LEFT and DOWN key decrease slider value.
</li>
</ul>
</div>
</div>
</div>
<button type="button" class="btn btn-default scroll-top" aria-label="Go to Top" id="scroll_top" onclick="topFunction()">
<i class="fa fa-chevron-up" aria-hidden="true"></i>
</button>
<footer>
<p>
© 2021 <a href="https://www.linkedin.com/in/md-asif-ahmed-oni-57271673/">Md Asif Ahmed Oni</a> / A11yWrapper. |
Check the project in <a href="https://github.com/oni20/A11yWrapper" target="_blank">GitHub</a> |
Licensed under the MIT license.
</p>
</footer>
</div>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"
integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"
integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"
integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn"
crossorigin="anonymous"></script>
<script src="dist/js/A11yWrapper.min.js" type="text/javascript"></script>
<script type="text/javascript">
var mybutton = document.getElementById("scroll_top");
// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function () { scrollFunction() };
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
mybutton.style.display = "block";
} else {
mybutton.style.display = "none";
}
}
// When the user clicks on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}
</script>
<script type="text/javascript">
var sliderOption = {
id:'slider_1',
min: 0,
max: 255,
now: 50,
stepper: 0,
label: 'Slider label',
output: '#sliderVal',
onSliderChange: function (data) {
console.log('Selected Item: ', data);
}
};
var multiSliderOption1 = {
id:'slider_2',
min: 0,
max: 100,
now: 10,
css:{
thumbColor: '#6e6d6d',
borderColor: '#d7d0d0',
fillColor: '#a4a1a1',
backgroundColor: '#f3f0f0'
},
label: 'Multi Slider 1',
output: '#sliderValMulti1',
onSliderChange: function (data) {
console.log('Selected Item: ', data);
}
},
multiSliderOption2 = {
id:'slider_3',
min: 0,
max: 255,
now: 50,
color: '#0fa683',
label: 'Multi Slider 2',
output: '#sliderValMulti2',
onSliderChange: function (data) {
console.log('Selected Item: ', data);
}
};
window.addEventListener('load', function () {
window.A11yWrapper('#idSliders1').slider(sliderOption);
window.A11yWrapper('.multi-slider-container').slider(multiSliderOption1, multiSliderOption2);
});
</script>
</body>
</html>