-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
510 lines (423 loc) · 23.8 KB
/
index.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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>z-carousel</title>
<link rel="stylesheet" href="./src/index.css" />
<link rel="stylesheet" href="./src/demo.css" />
<script type="module" src="./src/index.ts"></script>
<link href="https://unpkg.com/prismjs@1/themes/prism-twilight.min.css" rel="stylesheet" />
<script src="https://unpkg.com/prismjs@1/components/prism-core.min.js" defer></script>
<script src="https://unpkg.com/prismjs@1/plugins/autoloader/prism-autoloader.min.js" defer></script>
</head>
<body>
<header>
<div class="container">
<h1>
<span class="logo">z-carousel</span>
demo
</h1>
<div class="ext-links">
<a href="https://github.com/benavern/z-carousel" title="github" target="_blank" class="ext-logo">
<svg xmlns="http://www.w3.org/2000/svg" width="32px" height="32px" viewBox="0 0 96 96">
<path fill-rule="evenodd" clip-rule="evenodd" fill="currentColor"
d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z" />
</svg>
</a>
<a href="https://www.npmjs.com/package/@benavern/z-carousel" title="npm" target="_blank"
class="ext-logo">
<svg xmlns="http://www.w3.org/2000/svg" width="32px" height="32px" viewBox="0 0 32 32"
fill="currentColor">
<path
d="M7.415 7.656l17.291 0.024-0.011 17.29h-4.329l0.012-12.974h-4.319l-0.010 12.964h-8.656zM3.207 1.004c-0.002 0-0.003 0-0.005 0-1.214 0-2.198 0.984-2.198 2.198 0 0.002 0 0.004 0 0.006v-0 25.585c0 0.002 0 0.003 0 0.005 0 1.214 0.984 2.198 2.198 2.198 0.002 0 0.004 0 0.006 0h25.585c0.002 0 0.003 0 0.005 0 1.214 0 2.198-0.984 2.198-2.198 0-0.002 0-0.004 0-0.006v0-25.585c0-0.002 0-0.003 0-0.005 0-1.214-0.984-2.198-2.198-2.198-0.002 0-0.004 0-0.006 0h0z" />
</svg>
</a>
</div>
</div>
</header>
<section>
<div class="container">
<h2 id="get-started">Get started</h2>
<p>
<code>z-carousel</code> is available on npm, published as <code>@benavern/z-carousel</code>.
</p>
<br>
<h3>npm</h3>
<p>The component is available <a href="https://www.npmjs.com/package/@benavern/z-carousel">here on npm</a>,
you can install it via this command:</p>
<pre><code class="language-bash">npm i @benavern/z-carousel</code></pre>
<p>Then you can use it in your scripts like so in your js/ts module files: </p>
<pre><code class="language-ts">import '@benavern/z-carousel';</code></pre>
<hr>
<h3>CDN</h3>
<pre><code class="language-html"><script type="module" src="https://unpkg.com/@benavern/z-carousel"></script></code></pre>
<hr>
<h3>Have fun</h3>
<p>For example you can use it to display a slider of images</p>
<pre><code class="language-html"><z-carousel>
<img src="https://picsum.photos/960/540?random=1">
<img src="https://picsum.photos/960/540?random=2">
</z-carousel></code></pre>
<z-carousel>
<img src="https://picsum.photos/960/540?random=1" loading="lazy">
<img src="https://picsum.photos/960/540?random=2" loading="lazy">
</z-carousel>
<p>Any HTML will work</p>
<pre><code class="language-html"><z-carousel>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Inventore vel recusandae quae accusamus, dolore facilis maxime laboriosam quod provident magni in voluptates unde ex. Eveniet ex a expedita numquam soluta?
</p>
<p>
Earum voluptas eius modi consequatur debitis omnis excepturi enim dolorum aut eos. Illum consequatur, commodi, temporibus doloribus unde laboriosam quam adipisci cum, obcaecati incidunt animi dolore quo accusantium possimus voluptatem?
</p>
</z-carousel></code></pre>
<z-carousel>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Inventore vel recusandae quae accusamus,
dolore facilis maxime laboriosam quod provident magni in voluptates unde ex. Eveniet ex a expedita
numquam soluta?
</p>
<p>
Earum voluptas eius modi consequatur debitis omnis excepturi enim dolorum aut eos. Illum
consequatur, commodi, temporibus doloribus unde laboriosam quam adipisci cum, obcaecati incidunt
animi dolore quo accusantium possimus voluptatem?
</p>
</z-carousel>
</div>
</section>
<section>
<div class="container">
<h2 id="base">Base</h2>
<p>
Here is the raw component, you can add anything inside. Each root element will be considered as a slide
unless you use one of the defined slots.
</p>
<p>
To interact with the carousel on (non-touch) desktop, give focus to the component (tab through the
document) and start using keyboard arrows.
</p>
<p>
You can also scroll horizontaly with your mouse if it can do it.
</p>
<p>
On mobile, you can swipe with your finger from page to page.
</p>
<figure>
<z-carousel>
<img src="https://picsum.photos/960/540?random=base-1" loading="lazy">
<img src="https://picsum.photos/960/540?random=base-2" loading="lazy">
<img src="https://picsum.photos/960/540?random=base-3" loading="lazy">
<img src="https://picsum.photos/960/540?random=base-4" loading="lazy">
<img src="https://picsum.photos/960/540?random=base-5" loading="lazy">
<img src="https://picsum.photos/960/540?random=base-6" loading="lazy">
<img src="https://picsum.photos/960/540?random=base-7" loading="lazy">
<img src="https://picsum.photos/960/540?random=base-8" loading="lazy">
</z-carousel>
</figure>
</div>
</section>
<section>
<div class="container">
<h2 id="drag">Drag</h2>
<p>
You can use the <code>drag</code> attribute to enable swiping on non-touch devices.
</p>
<p>
This should not do anything on touch devices as it already is touch friendly
</p>
<figure>
<z-carousel drag>
<img src="https://picsum.photos/960/540?random=drag-1" loading="lazy">
<img src="https://picsum.photos/960/540?random=drag-2" loading="lazy">
<img src="https://picsum.photos/960/540?random=drag-3" loading="lazy">
<img src="https://picsum.photos/960/540?random=drag-4" loading="lazy">
<img src="https://picsum.photos/960/540?random=drag-5" loading="lazy">
<img src="https://picsum.photos/960/540?random=drag-6" loading="lazy">
<img src="https://picsum.photos/960/540?random=drag-7" loading="lazy">
<img src="https://picsum.photos/960/540?random=drag-8" loading="lazy">
</z-carousel>
</figure>
</div>
</section>
<section>
<div class="container">
<h2 id="navigation">Navigation</h2>
<p>
You can add navigation buttons. When a navigation is possible, it can be clicked, otherwize, the button
will be disabled.
</p>
<figure>
<z-carousel navigation>
<img src="https://picsum.photos/960/540?random=nav-1" loading="lazy">
<img src="https://picsum.photos/960/540?random=nav-2" loading="lazy">
<img src="https://picsum.photos/960/540?random=nav-3" loading="lazy">
<img src="https://picsum.photos/960/540?random=nav-4" loading="lazy">
<img src="https://picsum.photos/960/540?random=nav-5" loading="lazy">
<img src="https://picsum.photos/960/540?random=nav-6" loading="lazy">
<img src="https://picsum.photos/960/540?random=nav-7" loading="lazy">
<img src="https://picsum.photos/960/540?random=nav-8" loading="lazy">
</z-carousel>
</figure>
<hr>
<p>
By default, the navigation buttons are provided with html arrow entities <code>&lsaquo;</code>
(‹) and <code>&rsaquo;</code> (›).
</p>
<p>
It is possible to customize the content of the navigation buttons by using the
<code>slot="nav-prev"</code> and <code>slot="nav-next"</code> slots.
</p>
<figure>
<z-carousel navigation>
<img src="https://picsum.photos/960/540?random=nav-slot-1" loading="lazy">
<img src="https://picsum.photos/960/540?random=nav-slot-2" loading="lazy">
<img src="https://picsum.photos/960/540?random=nav-slot-3" loading="lazy">
<img src="https://picsum.photos/960/540?random=nav-slot-4" loading="lazy">
<img src="https://picsum.photos/960/540?random=nav-slot-5" loading="lazy">
<img src="https://picsum.photos/960/540?random=nav-slot-6" loading="lazy">
<img src="https://picsum.photos/960/540?random=nav-slot-7" loading="lazy">
<img src="https://picsum.photos/960/540?random=nav-slot-8" loading="lazy">
<span slot="nav-prev">
Before
</span>
<span slot="nav-next">
After
</span>
</z-carousel>
<figcaption>
<pre><code class="language-html"><span slot="nav-prev">
Before
</span>
<span slot="nav-next">
After
</span></code></pre>
</figcaption>
</figure>
</div>
</section>
<section>
<div class="container">
<h2 id="infinit">Infinit</h2>
<p>It is possible to cycle threw the carousel with the <code>infinit</code> attribute.</p>
<figure>
<z-carousel navigation infinit>
<img src="https://picsum.photos/960/540?random=infinit-1" loading="lazy">
<img src="https://picsum.photos/960/540?random=infinit-2" loading="lazy">
<img src="https://picsum.photos/960/540?random=infinit-3" loading="lazy">
<img src="https://picsum.photos/960/540?random=infinit-4" loading="lazy">
<img src="https://picsum.photos/960/540?random=infinit-5" loading="lazy">
<img src="https://picsum.photos/960/540?random=infinit-6" loading="lazy">
<img src="https://picsum.photos/960/540?random=infinit-7" loading="lazy">
<img src="https://picsum.photos/960/540?random=infinit-8" loading="lazy">
</z-carousel>
</figure>
</div>
</section>
<section>
<div class="container">
<h2 id="current-page">Current page</h2>
<p>
It is possible initialize the carousel on a given page with the <code>current-page</code> attribute
</p>
<figure>
<z-carousel class="ooooh" navigation current-page="2">
<img src="https://picsum.photos/960/540?random=current-slide-index-1" loading="lazy">
<img src="https://picsum.photos/960/540?random=current-slide-index-2" loading="lazy">
<img src="https://picsum.photos/960/540?random=current-slide-index-3" loading="lazy">
<img src="https://picsum.photos/960/540?random=current-slide-index-4" loading="lazy">
<img src="https://picsum.photos/960/540?random=current-slide-index-5" loading="lazy">
<img src="https://picsum.photos/960/540?random=current-slide-index-6" loading="lazy">
<img src="https://picsum.photos/960/540?random=current-slide-index-7" loading="lazy">
<img src="https://picsum.photos/960/540?random=current-slide-index-8" loading="lazy">
</z-carousel>
</figure>
</div>
</section>
<section>
<div class="container">
<h2 id="per-page">Multiple items per page</h2>
<p>You can decide to display multiple slides per page.</p>
<figure>
<z-carousel navigation per-page="3">
<img src="https://picsum.photos/320/180?random=per-page-1" loading="lazy">
<img src="https://picsum.photos/320/180?random=per-page-2" loading="lazy">
<img src="https://picsum.photos/320/180?random=per-page-3" loading="lazy">
<img src="https://picsum.photos/320/180?random=per-page-4" loading="lazy">
<img src="https://picsum.photos/320/180?random=per-page-5" loading="lazy">
<img src="https://picsum.photos/320/180?random=per-page-6" loading="lazy">
<img src="https://picsum.photos/320/180?random=per-page-7" loading="lazy">
<img src="https://picsum.photos/320/180?random=per-page-8" loading="lazy">
</z-carousel>
</figure>
</div>
</section>
<section>
<div class="container">
<h2 id="pagination">Pagination</h2>
<p>
You can add a fraction counter for pagination, this will show the current page number over the total
pages number
</p>
<figure>
<z-carousel navigation pagination per-page="3">
<img src="https://picsum.photos/960/540?random=pagination-1" loading="lazy">
<img src="https://picsum.photos/960/540?random=pagination-2" loading="lazy">
<img src="https://picsum.photos/960/540?random=pagination-3" loading="lazy">
<img src="https://picsum.photos/960/540?random=pagination-4" loading="lazy">
<img src="https://picsum.photos/960/540?random=pagination-5" loading="lazy">
<img src="https://picsum.photos/960/540?random=pagination-6" loading="lazy">
<img src="https://picsum.photos/960/540?random=pagination-7" loading="lazy">
<img src="https://picsum.photos/960/540?random=pagination-8" loading="lazy">
</z-carousel>
</figure>
</div>
</section>
<section>
<div class="container">
<h2 id="gap">Gap</h2>
<p>You can add a little bit of space betwin the slides by using the <code>gap</code> property.</p>
<figure>
<z-carousel navigation pagination per-page="3" gap="20">
<img src="https://picsum.photos/320/180?random=per-page-1" loading="lazy">
<img src="https://picsum.photos/320/180?random=per-page-2" loading="lazy">
<img src="https://picsum.photos/320/180?random=per-page-3" loading="lazy">
<img src="https://picsum.photos/320/180?random=per-page-4" loading="lazy">
<img src="https://picsum.photos/320/180?random=per-page-5" loading="lazy">
<img src="https://picsum.photos/320/180?random=per-page-6" loading="lazy">
<img src="https://picsum.photos/320/180?random=per-page-7" loading="lazy">
<img src="https://picsum.photos/320/180?random=per-page-8" loading="lazy">
</z-carousel>
</figure>
</div>
</section>
<section>
<div class="container">
<h2 id="dots">Dots</h2>
<p>
You can show dots for every page, each dot has the page number as text in it.
</p>
<p>
The current one is not clickable and the others will slide the carousel to the corresponding page when
clicked.
</p>
<figure>
<z-carousel navigation pagination dots>
<img src="https://picsum.photos/960/540?random=dots-1" loading="lazy">
<img src="https://picsum.photos/960/540?random=dots-2" loading="lazy">
<img src="https://picsum.photos/960/540?random=dots-3" loading="lazy">
<img src="https://picsum.photos/960/540?random=dots-4" loading="lazy">
<img src="https://picsum.photos/960/540?random=dots-5" loading="lazy">
<img src="https://picsum.photos/960/540?random=dots-6" loading="lazy">
<img src="https://picsum.photos/960/540?random=dots-7" loading="lazy">
<img src="https://picsum.photos/960/540?random=dots-8" loading="lazy">
</z-carousel>
</figure>
</div>
</section>
<section>
<div class="container">
<h2 id="disabled">Disabled</h2>
<p>
You can disable all interaction on the element with the <code>disabled</code> attribute.
</p>
<p>
You can still use the component methods programaticaly.
</p>
<p>
<button id="disabled-demo-btn">
Toggle disabled
</button>
</p>
<figure>
<z-carousel navigation pagination dots drag id="disabled-demo">
<img src="https://picsum.photos/960/540?random=disabled-1" loading="lazy">
<img src="https://picsum.photos/960/540?random=disabled-2" loading="lazy">
<img src="https://picsum.photos/960/540?random=disabled-3" loading="lazy">
<img src="https://picsum.photos/960/540?random=disabled-4" loading="lazy">
<img src="https://picsum.photos/960/540?random=disabled-5" loading="lazy">
<img src="https://picsum.photos/960/540?random=disabled-6" loading="lazy">
<img src="https://picsum.photos/960/540?random=disabled-7" loading="lazy">
<img src="https://picsum.photos/960/540?random=disabled-8" loading="lazy">
</z-carousel>
</figure>
</div>
</section>
<section>
<div class="container">
<h2 id="events">Events</h2>
<p>
A <code>change</code> event fires when the component is about to change page.
</p>
<p>
This event is a <a href="https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent">CustomEvent</a>, you have acces to <code>current</code> and <code>next</code> page numbers in the event detail object and it is cancelable.
</p>
<figure>
<z-carousel navigation pagination dots id="event-demo">
<img src="https://picsum.photos/960/540?random=events-1" loading="lazy">
<img src="https://picsum.photos/960/540?random=events-2" loading="lazy">
<img src="https://picsum.photos/960/540?random=events-3" loading="lazy">
<img src="https://picsum.photos/960/540?random=events-4" loading="lazy">
<img src="https://picsum.photos/960/540?random=events-5" loading="lazy">
<img src="https://picsum.photos/960/540?random=events-6" loading="lazy">
<img src="https://picsum.photos/960/540?random=events-7" loading="lazy">
<img src="https://picsum.photos/960/540?random=events-8" loading="lazy">
</z-carousel>
<figcaption>
<pre><code class="language-ts">document.querySelector('z-carousel#event-demo')?.addEventListener('change', (event) => {
console.log(event);
if ((event as CustomEvent).detail.next === 5) {
event.preventDefault();
alert('this action has been canceled!');
}
});</code></pre>
</figcaption>
</figure>
</div>
</section>
<section>
<div class="container">
<h2 id="full-demo">Full demo</h2>
<p>
Here is an example of what you could achieve with this component and a little bit of css styling: <a
href="https://github.com/benavern/z-carousel/blob/main/src/demo.css">See CSS</a>
</p>
<figure>
<z-carousel class="styled" navigation pagination per-page="2" gap="20" dots drag>
<img src="https://picsum.photos/960/540?random=styled-1" loading="lazy">
<img src="https://picsum.photos/960/540?random=styled-2" loading="lazy">
<img src="https://picsum.photos/960/540?random=styled-3" loading="lazy">
<img src="https://picsum.photos/960/540?random=styled-4" loading="lazy">
<img src="https://picsum.photos/960/540?random=styled-5" loading="lazy">
<img src="https://picsum.photos/960/540?random=styled-6" loading="lazy">
<img src="https://picsum.photos/960/540?random=styled-7" loading="lazy">
<img src="https://picsum.photos/960/540?random=styled-8" loading="lazy">
<svg slot="nav-prev" xmlns="http://www.w3.org/2000/svg" width="24px" height="24px"
viewBox="0 0 24 24">
<path d="M6 12H18M6 12L11 7M6 12L11 17" stroke="currentColor" stroke-width="2"
stroke-linecap="round" stroke-linejoin="round" />
</svg>
<svg slot="nav-next" xmlns="http://www.w3.org/2000/svg" width="24px" height="24px"
viewBox="0 0 24 24">
<path d="M6 12H18M18 12L13 7M18 12L13 17" stroke="currentColor" stroke-width="2"
stroke-linecap="round" stroke-linejoin="round" />
</svg>
</z-carousel>
<figcaption>
<p>You can style some <code>::part()</code> elements of the component</p>
<pre><code class="language-css">::part(content)
::part(nav-btn /* nav-btn--prev nav-btn--next nav-btn--disabled */)
::part(pagination)
::part(dots)
::part(dots-item /* dots-item--active */)</code></pre>
</figcaption>
</figure>
</div>
</section>
<footer>
<div class="container">
© <a href="https://benjamin.caradeuc.info">Benjamin Caradeuc</a> 2024
</div>
</footer>
</body>
</html>