Data
Carousel <pm-carousel>
Carousel built on native scroll-snap (swipe, trackpad and keyboard scrolling just work).
Overview
Optional autoplay (autoplay="5000") moves on every so many milliseconds. It waits while the pointer is over the carousel, while it is off screen and while the tab is hidden; it stops for good once keyboard focus moves into it (until Play is pressed); and it is off with reduced motion. The Play / Pause button (WCAG 2.2.2) shows whenever autoplay can run; paused, play() and stop() drive it from code.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
prev-labelprop: prevLabel | string | — | Name of the previous button (default "Previous slide"), for another language. |
next-labelprop: nextLabel | string | — | Name of the next button (default "Next slide"). |
label | string | Carousel | Accessible name (and visible label where the component shows one). |
per-viewprop: perView | number | 1 | Slides visible at once. |
gap | string | — | CSS gap between slides. |
loop | boolean | false | Wrap around at the ends. |
autoplay | number | 0 | Autoplay interval in ms (0 = off; at least 1500). |
hide-controlsprop: hideControls | boolean | false | Hide the previous/next buttons. |
hide-dotsprop: hideDots | boolean | false | Hide the slide position dots. |
paused | boolean | false | Autoplay is stopped (by the Play / Pause button, keyboard focus, or code). |
pause-labelprop: pauseLabel | string | — | Name of the button while slides play (default "Pause slides"). |
play-labelprop: playLabel | string | — | Name of the button while paused (default "Play slides"). |
Also accepts the contextual attributes tone, surface, radius, density, motion, elevation. They are inherited from ancestors' data-* attributes.
Events
| Event | React / Svelte prop | Description |
|---|---|---|
pm-change | onPmChange | Active slide changed. |
pm-toggle | onPmToggle | Autoplay was paused or resumed (paused). |
Slots
| Slot | Description |
|---|---|
(default) | Slides (any elements). |
Methods
play(), stop(), goTo(), next(), prev()