-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCarousel.html
706 lines (666 loc) · 36.9 KB
/
Carousel.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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
<!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 Carousel</title>
</head>
<body>
<div class="jumbotron">
<div class="container">
<h1 class="display-3">Carousel</h1>
<p>
Make an efficient use of this light-weight carousel component by just calling it at initial load with minimal
changes, few configurations and then the library will take over to create animation control, access
button and on top of that,
adapt all necessary accessibility attributes.
</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">Carousel</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="carousel1" class="carousel">
<div class="carousel-container">
<ul>
<li class="slide">
<div>
<a href="#">
<img src="https://www.w3schools.com/howto/img_mountains_wide.jpg"
style="width:100%">
</a>
<div class="text" style="
font-size: 15px;
width: 100%;
text-align: center;
color: black;
">Caption One</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
ut
aliquip ex ea commodo consequat.
</p>
</div>
</li>
<li class="slide">
<div>
<img src="https://www.w3schools.com/howto/img_mountains_wide.jpg"
style="width:100%">
<div class="text" style="
font-size: 15px;
width: 100%;
text-align: center;
color: black;
">Caption two
<a href="#">Test Link</a>
</div>
</div>
</li>
<li class="slide">
<div>
<img src="https://www.w3schools.com/howto/img_snow_wide.jpg" style="width:100%">
<div class="text" style="
font-size: 15px;
width: 100%;
text-align: center;
color: black;
">Caption Three</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
ut
aliquip ex ea commodo consequat.
</p>
</div>
</li>
<li class="slide">
<div>
<img src="https://www.w3schools.com/howto/img_nature_wide.jpg" style="width:100%">
<div class="text" style="
font-size: 15px;
width: 100%;
text-align: center;
color: black;
">Caption Four</div>
</div>
</li>
</ul>
</div>
</div>
<div id="init" class="mt-5">
<h2>Initial setup</h2>
<p>
Paste below HTML structure at your code where you want Carousel to appear. Any ID should be fine but make sure following
class name are used. This is necessary to pull styles from the CSS file. These CSS can be customized as well.
Any kind of design can be put inside <li></li> element.
</p>
<pre>
<code>
<span>
<div id="carousel1" class="carousel1">
<div class="carousel-container">
<ul>
<li class="slide">
...
</li>
<li class="slide">
...
</li>
<li class="slide">
...
</li>
<li class="slide">
...
</li>
</ul>
</div>
</div>
</span>
</code>
</pre>
<p>Call the slider component from Wrapper library and Slider</p>
<pre>
<code>
<span>
var carouselOptions = {
slidenav: true,
animate: false,
animationTimeSlots: [2, 4, 2, 3], // Number in seconds
animationType: "fade", // accepted value -> rtl, fade
startAnimated: true,
language: "EN",
liveSRText: "Merchandise %current% of %total%",
Buttons: {
controlButtons: {
"isIcon": false,
"prev": {
"icon": "<img alt='Previous Item' src='https://www.w3.org/WAI/tutorials/img/chevron-left-75c7dd0b.png' />",
"ariaText": "Previous"
},
"next": {
"icon": "<img alt='Previous Item' src='https://www.w3.org/WAI/tutorials/img/chevron-right-2f19bc8b.png' />",
"ariaText": "Next"
}
},
animationButtons: {
"play": {
"icon": "▶",
"ariaText": "Stop Animation"
},
"pause": {
"icon": "■",
"ariaText": "Start Animation"
}
},
slideNavButtons: {
"activeItemSRText": "(Current Item)",
"itemDescriptionSRText": "Merchandise"
}
}
};
window.onload = (event) => {
window.A11yWrapper('.carousel1').carousal(carouselOptions);
};
OR
window.addEventListener('load', function () {
window.A11yWrapper('.carousel1').carousal(carouselOptions);
});
OR
//jQuery Users
$( document ).ready(function() {
window.A11yWrapper('.carousel1').carousal(carouselOptions);
});
</span>
</code>
</pre>
</div>
<div id="configuration">
<h2>Configuration</h2>
<p>
All sort of customization need to be passed as an Object.
Carousel 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>slidenav</td>
<td>Boolean</td>
<td>
<p><strong>true:</strong> Display carousel navigation control at the bottom of each slide</p>
<p><strong>false:</strong> Hide navigation control</p>
</td>
</tr>
<tr>
<td>animate</td>
<td>Boolean</td>
<td>
This will impact if only <strong>slidenav</strong> key value set to true.
<p class='mt-3'><strong>true:</strong> Show Play/ Pause buttons</p>
<p><strong>false:</strong> Hide Play/ Pause buttons</p>
</td>
</tr>
<tr>
<td>animationTimeSlots</td>
<td>array of integers</td>
<td>Number inside array defines seconds for each slide. For an example,
consider Carousel has 3 slides. First and last slide will move in every 3 seconds and second slide will move
faster like 1 seconds. In that case, pass [3,1,3]. Here each number will be assigned to slide suquentially.
<p class='mt-3'>
Passing one item in array will assign the time to all sliders. For an example - [2] will assign 2 seconds
delay to all slides. Default time is [3]
</p>
</td>
</tr>
<tr>
<td>animationType</td>
<td>String</td>
<td>Only supported type is 'fade'. 'rtl' (Right to left) and 'ltr' (Left to right) is in progress</td>
</tr>
<tr>
<td>startAnimated</td>
<td>Boolean</td>
<td>
<p><strong>true:</strong> Carousel start animation on page load</p>
<p><strong>false:</strong> Animation won't start</p>
</td>
</tr>
<tr>
<td>language</td>
<td>String</td>
<td>
This option is meant for localization. Work is in progress !!
</td>
</tr>
<tr>
<td>liveSRText</td>
<td>String</td>
<td>
Screen reader content stating type of carousel any which number is displaying out of total number of slides.
Format is important to show current slide and total slide number. Following format is allowed
<code>
"Any text %current% of %total%",
</code>
Here <strong>%current%</strong> and <strong>%total%</strong> are fixed words for the library and will be replaced with actual number dynamically.
</td>
</tr>
<tr>
<td>Buttons</td>
<td>Object</td>
<td>
This object contains following keys to hold information about icons and screen reader contents
<ul>
<li><strong>controlButtons</strong>
<ul>
<li><strong>isIcon</strong> - This is Boolean type and determine whether icon tag passed on following keys or not.
<p class="mt-2"><strong>true:</strong> Icons will be treated as HTML element and place on PAGE</p>
<p><strong>false:</strong> Icons will be considered as plain text</p>
</li>
<li><strong>prev</strong>
<ul>
<li><strong>icon</strong> - This is String type and accept any icon or image tag passed as string</li>
<li><strong>ariaText</strong> - Screen reader text for the icon</li>
</ul>
</li>
<li><strong>next</strong>
<ul>
<li><strong>icon</strong> - This is String type and accept any icon or image tag passed as string</li>
<li><strong>ariaText</strong> - Screen reader text for the icon</li>
</ul>
</li>
</ul>
</li>
<li><strong>animationButtons</strong>
<ul>
<li><strong>play</strong>
<ul>
<li><strong>icon</strong> - This is String type and accept any icon or image tag passed as string</li>
<li><strong>ariaText</strong> - Screen reader text for the icon</li>
</ul>
</li>
<li><strong>pause</strong>
<ul>
<li><strong>icon</strong> - This is String type and accept any icon or image tag passed as string</li>
<li><strong>ariaText</strong> - Screen reader text for the icon</li>
</ul>
</li>
</ul>
</li>
<li><strong>slideNavButtons</strong>
<ul>
<li><strong>activeItemSRText</strong> - This is String type. This field describes active carousel item</li>
<li><strong>itemDescriptionSRText</strong> - This is String type. This field describes type of carousel item</li>
</ul>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="multiple">
<h2>How to use Carousel component multiple times</h2>
<div class="mt-2 mb-1">
<div id="carousel2" class="multi-carousel">
<div class="carousel-container">
<ul>
<li class="slide">
<div>
<a href="#">
<img src="https://www.w3schools.com/howto/img_mountains_wide.jpg" style="width:100%">
</a>
<div class="text" style="
font-size: 15px;
width: 100%;
text-align: center;
color: black;
">Caption One</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
ut
aliquip ex ea commodo consequat.
</p>
</div>
</li>
<li class="slide">
<div>
<img src="https://www.w3schools.com/howto/img_mountains_wide.jpg" style="width:100%">
<div class="text" style="
font-size: 15px;
width: 100%;
text-align: center;
color: black;
">Caption two
<a href="#">Test Link</a>
</div>
</div>
</li>
<li class="slide">
<div>
<img src="https://www.w3schools.com/howto/img_snow_wide.jpg" style="width:100%">
<div class="text" style="
font-size: 15px;
width: 100%;
text-align: center;
color: black;
">Caption Three</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
ut
aliquip ex ea commodo consequat.
</p>
</div>
</li>
<li class="slide">
<div>
<img src="https://www.w3schools.com/howto/img_nature_wide.jpg" style="width:100%">
<div class="text" style="
font-size: 15px;
width: 100%;
text-align: center;
color: black;
">Caption Four</div>
</div>
</li>
</ul>
</div>
</div>
</div>
<div class="mb-1">
<div id="carousel3" class="multi-carousel">
<div class="carousel-container">
<ul>
<li class="slide">
<div>
<a href="#">
<img src="https://www.w3schools.com/howto/img_mountains_wide.jpg" style="width:100%">
</a>
<div class="text" style="
font-size: 15px;
width: 100%;
text-align: center;
color: black;
">Caption One</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
ut
aliquip ex ea commodo consequat.
</p>
</div>
</li>
<li class="slide">
<div>
<img src="https://www.w3schools.com/howto/img_mountains_wide.jpg" style="width:100%">
<div class="text" style="
font-size: 15px;
width: 100%;
text-align: center;
color: black;
">Caption two
<a href="#">Test Link</a>
</div>
</div>
</li>
<li class="slide">
<div>
<img src="https://www.w3schools.com/howto/img_snow_wide.jpg" style="width:100%">
<div class="text" style="
font-size: 15px;
width: 100%;
text-align: center;
color: black;
">Caption Three</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
ut
aliquip ex ea commodo consequat.
</p>
</div>
</li>
<li class="slide">
<div>
<img src="https://www.w3schools.com/howto/img_nature_wide.jpg" style="width:100%">
<div class="text" style="
font-size: 15px;
width: 100%;
text-align: center;
color: black;
">Caption Four</div>
</div>
</li>
</ul>
</div>
</div>
</div>
<p>
Carousel can be positioned in multiple places while initiating the library. Also, multiple carousel
can have different configurations as well. Below two ways, Carousel can be called several times.
</p>
<ul>
<li>
Using multiple ID.
<p class="mt-3">
Call wrapper class multiple times for each distinctive ID.
</p>
<pre>
<code>
<span>
var carouselOption1 = {...},
carouselOption2 = {...};
window.addEventListener('load', function () {
window.A11yWrapper('#carousel_id_1').carousal(carouselOption1);
window.A11yWrapper('#carousel_id_2').carousal(carouselOption2);
});
</span>
</code>
</pre>
</li>
<li>
Using same class for multiple elements.
<p class="mt-3">
In below example, configuration object will be assigned sequentially. First object
will be assigned to first Carousel and second object will be assigned to second Carousel.
If only one configuration object is passed then both Carousels will be built upon that single
configuration object.
</p>
<pre>
<code>
<span>
var carouselOption1 = {...},
carouselOption2 = {...};
window.addEventListener('load', function () {
window.A11yWrapper('.carousel').carousal(carouselOption1, carouselOption2);
});
</span>
</code>
</pre>
</li>
</ul>
</div>
<div id="accessibility">
<h2>Accessibility</h2>
<p class="lead mt-3">Keyboard interaction</p>
<ul>
<li>
<strong>TAB</strong> - Press TAB key to focus on carousel controls and operate
</li>
<li>
<strong>MOUSE MOVE</strong> - MOUSE HOVER will stop the animation and live region describe the current slide information
</li>
<li>
<strong>ENTER</strong> - ENTER key press will select the slide or activate corresponding controls
</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 carouselOptions1 = {
slidenav: false,
animate: true,
animationTimeSlots: [2, 4, 2, 3], // Number in seconds
animationType: "fade", // accepted value -> rtl, fade
startAnimated: true,
language: "EN",
liveSRText: "Merchandise %current% of %total%",
Buttons: {
controlButtons: {
"isIcon": false,
"prev": {
"icon": "<img alt='Previous Item' src='https://www.w3.org/WAI/tutorials/img/chevron-left-75c7dd0b.png' />",
"ariaText": "Previous"
},
"next": {
"icon": "<img alt='Previous Item' src='https://www.w3.org/WAI/tutorials/img/chevron-right-2f19bc8b.png' />",
"ariaText": "Next"
}
},
animationButtons: {
"play": {
"icon": "▶",
"ariaText": "Stop Animation"
},
"pause": {
"icon": "■",
"ariaText": "Start Animation"
}
},
slideNavButtons: {
"activeItemSRText": "(Current Item)",
"itemDescriptionSRText": "Merchandise"
}
}
},
carouselOptions2 = {
slidenav: true,
animate: true,
animationTimeSlots: [3, 4, 2, 2],
animationType: "fade",
startAnimated: true,
language: "EN",
liveSRText: "New Merchandise %current% of %total%",
Buttons: {
controlButtons: {
"isIcon": false,
"prev": {
"icon": "<img alt='Previous Item' src='https://www.w3.org/WAI/tutorials/img/chevron-left-75c7dd0b.png' />",
"ariaText": "Previous"
},
"next": {
"icon": "<img alt='Previous Item' src='https://www.w3.org/WAI/tutorials/img/chevron-right-2f19bc8b.png' />",
"ariaText": "Next"
}
},
animationButtons: {
"play": {
"icon": "▶",
"ariaText": "Stop Animation"
},
"pause": {
"icon": "■",
"ariaText": "Start Animation"
}
},
slideNavButtons: {
"activeItemSRText": "(Current Item)",
"itemDescriptionSRText": "New Merchandise"
}
}
};
window.onload = (event) => {
window.A11yWrapper('.carousel').carousal(carouselOptions1);
window.A11yWrapper('.multi-carousel').carousal(carouselOptions1, carouselOptions2);
};
</script>
</body>
</html>