For the complete documentation index, see llms.txt. This page is also available as Markdown.

x-slideshow

Directives and magics for slideshows: slide registration, autoplay, and controls that stay in sync.

Directives and magics for slideshows: slide registration, autoplay, and controls that stay in sync.

Directive / magic
What it does

x-slideshow

The root. Holds the play state and the current slide index

x-slideshow.autoplay

Starts the show playing on load

x-slideshow.duration.5000ms

Sets how long each slide shows (default 1000ms)

x-slideshow="{ initialSlideIndex: 2 }"

Options object. state and currentSlideIndex accept get/set pairs

x-slideshow:viewport

Wraps the slides. Adds a carousel region, arrow-key navigation, and the $id('slideshow') id

x-slideshow:slide

Registers a slide (role="group", aria-roledescription="slide")

x-slideshow:prev / x-slideshow:next

Step buttons. Pause the show, then move

x-slideshow:play / x-slideshow:pause / x-slideshow:toggle

Play-state buttons

x-slideshow:control

Binds aria-controls to the viewport for a custom control

$slideshow

The state, readable anywhere inside the root: currentSlideIndex, totalSlides, next(), prev(), play(), pause(), toggle(), state, slideDuration

$slide

Inside x-slideshow:slide: slideIndex, isCurrentSlide, wasLastSlide

Left and right arrow keys change slides. Focus pauses autoplay. Slide changes are announced only while paused because aria-live changes to "off" during autoplay.

Examples

A basic slideshow

Use x-slideshow:slide with $slide.isCurrentSlide to show one slide at a time:

<div x-slideshow>
  <div x-slideshow:viewport>
    <div x-slideshow:slide x-show="$slide.isCurrentSlide">First</div>
    <div x-slideshow:slide x-show="$slide.isCurrentSlide">Second</div>
  </div>
  <button x-slideshow:prev>Previous</button>
  <button x-slideshow:next>Next</button>
</div>

Autoplay

Use the autoplay and duration modifiers to advance slides on a timer:

x-slideshow:prev and x-slideshow:next pause before changing slides. Add an x-slideshow:toggle or x-slideshow:pause button to an autoplaying slideshow. The viewport also pauses on focus.

Transitions between slides

Use x-transition on the slides, with $slide.wasLastSlide to style the slide on its way out:

wasLastSlide marks the slide that was current before the latest change. It is mid-exit while the new slide enters.

A progress bar

Use a CSS animation with the --slideshow-duration and --slideshow-play-state properties set by the root. This keeps smooth progress out of Alpine's reactive loop:

The animation pauses and resumes with the slideshow. Moving to another slide removes the animation from the old segment and starts it on the new one.

Opening on a specific slide

Use the initialSlideIndex option to pick the opening slide:

The product gallery uses this to open on the featured media of the selected variant.

Driving the slideshow from outside

Use get/set pairs in the options object to bind the slide index to your own state:

Anything inside the root can also set $slideshow.currentSlideIndex directly. The product gallery's thumbnail picker and variant-change handler both jump slides this way.

Options

Option
What it does

initialSlideIndex

The slide index to open on (default 0)

state

'playing' or 'paused'. Accepts a get/set pair for two-way binding

currentSlideIndex

The current slide. Accepts a get/set pair for two-way binding

autoplay and slideDuration are set through the modifiers, not the options object. To sync a slideshow with an accordion or tabs in a Pair section, see Pair sections.

Last updated

Was this helpful?