vUX / Carousel / v4.1.0

Slides that keep their place.

Autoplay, dots, swipe and hover-pause from one constructor and two elements you already have.

new Carousel(container, viewport).initialize(); // then .start()

01Playground

Every config property, applied live to a running carousel. No rebuild is needed for any of them; Destroy and Rebuild are here to show the teardown.

Config
styles ok
running
active0
interval2900ms
instance#1
autoplaying
Equivalent code

                

02Two on one page

Each instance owns its dots and its buttonStyle. Click a dot on one and the other does not notice; the styles are scoped to their own container.

delay 1800 · buttonStyle circle / amber glow
delay 3200 · buttonStyle bar / cyan

03Swipe and hover

With touchResponse on (the default) the carousel builds a TouchHandler on the container. Drag with a mouse or a finger. Pointing at the frame pauses autoplay; leaving resumes it.

pointer outside: autoplaying

← How a swipe resolves

A drag past a quarter of the frame's width commits to the neighbouring slide; anything shorter springs back. The first and last slides are end stops: swipes do not wrap, autoplay does.

When the swipe settles, the carousel marks that slide active and lights its dot, so autoplay continues from where your finger left it, not from where the timer thought it was.

While swiping is on, the container carries vTouchHandler, which gives it the grab cursor and touch-action:pan-y, so on a phone a horizontal swipe is not taken over by page scrolling.

04Bad input fails immediately

The constructor and every config setter validate on the spot and throw a message naming the offending argument. These buttons do the wrong thing on purpose.

No error yet: press one of the buttons above.