Liking cljdoc? Tell your friends :D

x-scroll

A flexible scroll container that supports horizontal and vertical carousel scrolling. Includes navigation controls, dot indicators, scroll-snap, auto-play, loop mode, and full keyboard/accessibility support.


Tag

<x-scroll></x-scroll>

Attributes

AttributeTypeDefaultDescription
modeenum"horizontal"Scroll direction: horizontal vertical
snapenum"none"Scroll-snap alignment: none start center end
loopbooleanfalseEnable infinite loop scrolling (requires 3+ children)
auto-playbooleanfalseAuto-advance slides on an interval
intervalnumber5000Milliseconds between auto-advance when auto-play is active
show-controlsstringtrueShow prev/next navigation buttons. Set "false" to hide.
show-indicatorsbooleanfalseShow dot indicators for current slide
active-indexnumber0Currently visible slide index (0-based)
gapnumber0Gap between children in pixels
disabledbooleanfalseDisables all interaction, controls, and auto-play
labelstring""Accessible label for the scroll region

Properties

PropertyTypeReflects attribute
modestringmode
snapstringsnap
loopbooleanloop
autoPlaybooleanauto-play
intervalnumberinterval
showControlsbooleanshow-controls
showIndicatorsbooleanshow-indicators
activeIndexnumberactive-index
gapnumbergap
disabledbooleandisabled
labelstringlabel

Methods

MethodArgumentsDescription
goTo(idx)idx: numberNavigate to a specific slide index
next()Navigate to the next slide
prev()Navigate to the previous slide

Events

EventBubblesComposedCancelableDetail
x-scroll-changeyesyesno{ activeIndex, previousIndex }
x-scroll-startyesyesno{ direction, activeIndex }
x-scroll-endyesyesno{ activeIndex }
x-scroll-loopyesyesyes{ direction }

direction is "forward" or "backward".

Calling event.preventDefault() on x-scroll-loop prevents the loop from occurring.


Slots

SlotDescription
(default)Child elements to scroll through. Each direct child is one slide.

CSS Custom Properties

PropertyDefaultDescription
--x-scroll-gap0pxGap between children
--x-scroll-padding0pxViewport padding
--x-scroll-border-radius0pxViewport border radius
--x-scroll-bgtransparentViewport background
--x-scroll-slide-size100%Slide flex-basis (width or height)
--x-scroll-control-size36pxPrev/next button size
--x-scroll-control-bgrgba(255,255,255,0.9)Button background
--x-scroll-control-colorrgba(0,0,0,0.7)Button icon color
--x-scroll-control-hover-bgrgba(255,255,255,1)Button hover background
--x-scroll-control-border-radius50%Button border radius
--x-scroll-control-shadow0 2px 8px rgba(0,0,0,.15)Button box shadow
--x-scroll-indicator-size8pxDot indicator diameter
--x-scroll-indicator-gap6pxGap between indicators
--x-scroll-indicator-colorrgba(0,0,0,0.25)Inactive dot color
--x-scroll-indicator-active-colorrgba(0,0,0,0.7)Active dot color
--x-scroll-transition-duration300msScroll transition duration
--x-scroll-disabled-opacity0.55Opacity when disabled
--x-scroll-focus-ringrgba(0,102,204,0.6)Focus ring color

All color properties have automatic dark-mode overrides.


Accessibility

  • Container uses role="region" with aria-roledescription="carousel" and aria-label
  • Prev/next buttons have appropriate aria-label and disabled states
  • Indicators use role="tablist" with role="tab" and aria-selected on each dot
  • An aria-live="polite" region announces slide changes
  • Keyboard: Arrow keys navigate slides (Left/Right for horizontal, Up/Down for vertical), Home/End jump to first/last
  • prefers-reduced-motion: reduce disables smooth scrolling transitions

Usage

Horizontal carousel with snap

<x-scroll snap="center" show-indicators gap="16" label="Featured products">
  <div>Slide 1</div>
  <div>Slide 2</div>
  <div>Slide 3</div>
</x-scroll>

Vertical scrolling

<x-scroll mode="vertical" style="height: 400px">
  <div>Section 1</div>
  <div>Section 2</div>
  <div>Section 3</div>
</x-scroll>

Auto-play carousel with loop

<x-scroll loop auto-play interval="3000" show-indicators label="Testimonials">
  <div>Quote 1</div>
  <div>Quote 2</div>
  <div>Quote 3</div>
</x-scroll>

Listening for events

const scroller = document.querySelector('x-scroll');
scroller.addEventListener('x-scroll-change', (e) => {
  console.log(`Changed to slide ${e.detail.activeIndex} from ${e.detail.previousIndex}`);
});

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close