Question presented to candidate: "You already know a basic carousel. Now make ours feel native: it must loop forever in one direction, so going from the last photo to the first slides forward instead of rewinding across every photo. Users on phones should be able to drag the photo with a finger and have it follow, then commit or snap back on release. Keep the arrows, dots, keyboard and a 3-second autoplay that pauses on hover, focus, while dragging and when the tab is hidden."
Requirements:
- One slide visible; the track is
[clone of last, ...slides, clone of first]and moves withtranslateX. - Next from the last slide animates onto the clone of the first, then jumps silently (transition off) to the real first slide; the same in reverse.
- Pointer drag (mouse, pen, touch) moves the track 1:1; release beyond 40px commits to the neighbour, otherwise it springs back.
- Clicks during a running transition are ignored; arrows, dots and Left / Right keys still work.
- Autoplay every 3 s, paused on hover, keyboard focus, while dragging and while
document.hidden; a Pause button.
What a strong answer should cover:
- Why the naive
index % ntrack rewinds, and how cloned edge slides plus a silent jump ontransitionendhide it. - Toggling
transition: nonefor the jump, forcing a reflow so the browser does not animate it, and a timeout fallback becausetransitionendnever fires with reduced motion (no transition runs) or when a transition is cancelled. - A transition lock so rapid clicks cannot run past the clones.
- Pointer Events with
setPointerCapture,touch-action: pan-yso vertical page scroll still works, a distance threshold, and not hijacking clicks on the arrow buttons. - Page Visibility API for autoplay, clones hidden from screen readers (
aria-hidden, emptyalt).
Clarifying questions expected:
- "Is a 40px threshold right, or should a fast flick with a short distance also count (velocity)?"
- "Should autoplay resume after a swipe, or stop once the user takes control?"
- "Do we need peeking neighbours (slides narrower than the viewport) or exactly one slide?"
Code / implementation expected: Yes. A working carousel with cloned edges, the silent jump, pointer swipe and autoplay with all pause conditions.