Classic case studies · mid
Case study: image carousel and gallery
A strong carousel design has a controlled/uncontrolled index API, moves slides with CSS transforms or scroll-snap, loads the current image eagerly and only neighbours next, supports swipe without breaking vertical scroll, and follows the APG carousel pattern with a pause control.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- API: items, index + onIndexChange (controlled) or defaultIndex, loop, autoplay interval, renderItem, thumbnails, aria label.
- Movement: transform: translateX(-index × 100%) (compositor-friendly) or CSS scroll-snap (native swipe and momentum); never animate left/width.
- Loading: current slide eager (fetchpriority high if it is the LCP image), preload neighbours, lazy-load the rest; srcset/sizes; reserve aspect ratio.
- Infinite loop: clone first/last slides and jump without a transition, or wrap the index with modulo ((i % n) + n) % n.
- Swipe: pointer events with a distance/velocity threshold; touch-action: pan-y so vertical page scroll still works.
- APG carousel: container role=region (or group) with aria-roledescription='carousel' and a label; slides role=group, aria-roledescription='slide'; a Stop/Start rotation button as the first control; stop rotation on hover and on keyboard focus; aria-live='off' while rotating, 'polite' when not.
- Respect prefers-reduced-motion (no autoplay, no slide animation); pause autoplay when the tab is hidden or the carousel is off-screen.
- Gallery/lightbox variant: thumbnail strip, zoom in a modal dialog, arrow keys, the photo index in the URL for sharing.
The red pen
Common traps: mistake → fix
Mistake: Autoplay without a pause button
Fix: fails WCAG and annoys users.
Mistake: Load all 50 high-resolution images up front
Fix: slow LCP and wasted data.
Mistake: i - 1 for 'previous' at index 0
Fix: negative index; JavaScript % keeps the sign.
Mistake: Animate left
Fix: layout on every frame and jank.
Easy to hard
Questions interviewers ask, easy to hard
- Design a product image carousel with thumbnails and swipe.
- There are 50 high-res images. What loads and when?
- How do you make autoplay accessible?
- How do you build an infinite loop without a visible jump?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.