HTML Attributes
start-active="integer" can be set with an integer value that represents the first slide to be active. For example, if you have 5 slides in your carousel, and you want the 3rd slide to be active on load, you could set start-active="3"
on your <slotted-carousel>
.
random-order add this attribute to a <slotted-carousel>
to show your [slot="slide"]
elements in a random order. This random order will also be reflected in the progress indicator ([slot="indicator"]
) elements, so that your slides and progress indicators show in the same order.
order='[{ "originalIndex": integer, "newIndex": integer }]' add this attribute to a <slotted-carousel>
to show your [slot="slide"]
elements in a custom order. This custom order will also be reflected in the progress indicator ([slot="indicator"]
) elements, so that your slides and progress indicators show order the same order. The value of the attribute should be JSON stringified value of an array that includes objects with two keys, originalIndex
which should be the slide's original position in the sequence of slides (0 indexed), and newIndex
which reflects the final position in the sequence of slides (also 0 indexed).
previous-key="keyCode"
next-key="keyCode" are used to define keyboard navigation. The value of these attributes should be an event.key
value from a keydown
event on the <slotted-carousel>
. For example, to use the arrow left key to go to the previous slide, and the arrow right key to go to the next slide, you could set these values as previous-key="ArrowLeft" next-key="ArrowRight"
.
expose-timer add this attribute to a <slotted-carousel>
element that has a <timer-normalized slot="timer">
element as its child, and the <slotted-carousel>
will have a CSS property --timer-normalized
with a floating point value from 0-1 of the timer's current progress through its duration
.
Behind the scenes the <slotted-carousel>
is listening for tick
events from its [slot="timer"]
child which should contain an event.detail.interval
value to echo into the --timer-normalized
CSS property.
expose-slide-count add this attribute to a <slotted-carousel>
to have the CSS property --slide-count
set as an integer value on the carousel element. This can be useful for determining z-index
values for your slides, or otherwise bounding the value space for CSS properties that lean on the slide count.
expose-active-slide add this attribute to a <slotted-carousel>
to have the CSS property --active-slide
set as an integer value on the carousel element.
touch-swipeable add this attribute to a <slotted-carousel>
to enable touch events for changing the active slide. Be default, swiping left will trigger the next slide method, swiping right will tiger the previous slide method. Use the swipe-{up,down,left-right}-action
attribute to modify this default behavior.
swipe-up-action
swipe-down-action
swipe-left-action
swipe-right-action attributes can be set to "next"
or "previous"
to map that swipe direction to the next or previous slide method.
CSS properties
--slide-count CSS property will be added to any <slotted-carousel>
with the expose-slide-count
attribute set on it.
--active-slide CSS property will be added to any <slotted-carousel>
with the expose-active-slide
attribute set on it.
--timer-normalized CSS property will be added to any <slotted-carousel>
with the expose-timer
attribute set on it, that also contains a [slot="timer"]
child.
JavaScript Events
ready event is emitted once the connectedCallback
is done running. This is where all event listeners are set up, after this event fires the element is ready to do everything that it does.
slide event is emitted at the end of the nextSlide
or previousSlide
method execution. The carousel.state
object value, which includes the activeSlide
and maxSlideIndex
will exist on event.detail
.