Skip to content
Español

Navigate

Type to search. Press Escape to close.

    Components · js

    Carousel

    A slideshow built on a list. The server sends slides in a horizontally scrolling track with scroll snapping, dots as plain anchor links and hidden buttons; that already works everywhere. On init the dots become tabs, the slides become panels, the buttons appear and the track is driven by transforms: slide with a parallax caption, crossfade, or a cinema mode that slowly zooms the active media. Autoplay draws a progress bar, pauses on hover, focus and hidden tabs, and never starts when the reader prefers reduced motion.

    CSS: css/components/carousel.css (in ivolt.css). JS: @intervolutions/ivolt/carousel or auto.js. Added in v0.3.

    Cinema effect with autoplay

    data-iv-effect="cinema" crossfades the slides and adds a slow zoom on the active media while the caption rises. With data-iv-autoplay the component adds a large counter and a progress bar that fills over the interval; the play/pause button exposes its state with aria-pressed.

    Thumbnails

    Give the dots the iv-carousel__dots--thumbs class and put a small image in each anchor: they become thumbnail tabs. This example uses the fade effect.

    With photographs

    Real images from Unsplash (credited in the captions), the cinema effect and a seven-second autoplay. The images live with the documentation, not in the package.

    Options

    OptionAttributeDefaultEffect
    effectdata-iv-effectslideslide, fade or cinema.
    autoplaydata-iv-autoplay0Milliseconds between slides; 0 disables autoplay. Never starts under reduced motion.
    loopdata-iv-looptrueWrap around at both ends.
    pauseOnHoverdata-iv-pause-on-hovertruePause autoplay while the pointer is over the carousel.
    swipedata-iv-swipetruePointer drag changes the slide (40 px threshold).
    durationdata-iv-duration600Transition length in milliseconds.
    pauseText, playTextdata-iv-pause-text, data-iv-play-textPause, PlayLabels of the toggle button.

    Methods and events

    next(), prev(), goTo(index), play(), pause(), destroy(); read index, count, isPlaying and slides. Events on the root element: iv:change (cancelable, detail.index, previousIndex, reason) then iv:changed; iv:play and iv:pause with a reason.

    Keyboard, gestures and assistive technology

    Left and Right move between slides from the tabs or from the viewport, Home and End jump, Enter and Space activate a tab. Dragging with a pointer changes the slide. The markup follows the tabbed carousel pattern: each slide is a panel labelled "n of N", non-visible slides are inert in the fade and cinema effects, and the viewport is a live region only while autoplay is paused, so the reader is not interrupted by every change.

    Without JavaScript

    The track scrolls horizontally and snaps to each slide, the dots are anchor links that scroll the matching slide into view, and the buttons stay hidden. Captions sit on a gradient scrim so the text stays readable on any media.

    Common mistakes

    • Media without alt text or an aria-label: every slide needs a name.
    • Autoplay on a carousel with links and forms inside: readers lose their place. Prefer manual navigation or a long interval.
    • Using the carousel for essential content: nothing important should only exist on slide four.

    Class index

    Parts and modifiers of this family that the examples above do not show. The full list per stylesheet lives in the reference.

    ClassWhat it does
    iv-carousel__scrimGradient laid over the slide so a caption stays legible on any photograph; generated by init when the carousel has captions.