Crossfading banner carousel with autoplay, pause, and arrows
The home page of a plant nursery’s online shop opens with a hero banner that cycles through promotions. The banners crossfade into each other instead of sliding. To keep the fade smooth, every banner image is loaded and decoded once and stays in the DOM: switching banners only changes which one is visible. Build the rotator, with autoplay, a Pause/Play toggle, and Previous/Next buttons.
The starter code includes the banners and the autoplay interval. The starter CSS already has a crossfade for a .hero-slide that gets the is-active class, but you can style it any way you like.
const AUTOPLAY_MS = 4000;
const SLIDES = [
{ headline: 'Spring Seed Sale', src: 'https://picsum.photos/id/292/800/320', alt: 'Seed packets on a potting bench' },
{ headline: 'Free Delivery Over $40', src: 'https://picsum.photos/id/1080/800/320', alt: 'Crate of fresh strawberries' },
{ headline: 'Balcony Planters Are Here', src: 'https://picsum.photos/id/106/800/320', alt: 'Window box full of petunias' },
{ headline: 'Saturday Pruning Workshops', src: 'https://picsum.photos/id/1067/800/320', alt: 'Gardener trimming a hedge' },
];
<img> (with src and alt) and its headline. The first slide is shown first.aria-hidden="true" on the element wrapping each other slide (its image and headline). Screen readers and the tests then only see the current one.Slide N of 4.aria-label) move one slide and wrap: Previous on slide 1 goes to slide 4, Next on slide 4 goes to slide 1.AUTOPLAY_MS, move to the next slide (wrapping from 4 to 1).
AUTOPLAY_MS after the click.AUTOPLAY_MS, moves exactly one more slide.Pause while autoplay runs and Play while it is paused.
Play resumes autoplay: the next automatic move happens a full AUTOPLAY_MS after the click.t = 0 Slide 1 of 4, "Spring Seed Sale"
t = 4000 Slide 2 of 4 (autoplay)
t = 7000 click Next Slide 3 of 4
t = 10000 still Slide 3 (the countdown restarted at 7000)
t = 11000 Slide 4 of 4
t = 15000 Slide 1 of 4 (wraps)
Click Pause button reads "Play"; waiting does nothing
Click Previous Slide 4 of 4 (still paused)
Click Play 4000 ms later: Slide 1 of 4
key per slide, not one that changes with the current index.The tests click your buttons and read the screen like a user would. You don’t need test ids, specific class names, or an exact HTML structure. The test frame is hidden, so real timers don’t run there: each test replaces setTimeout, setInterval and their clear functions with a fake clock and moves it forward by hand. They check that:
<img> elements, in SLIDES order, and exactly one of them is not inside an aria-hidden="true" element: the current slide.aria-hidden="true" doesn’t count).Slide N of 4 is shown.aria-label.Capitalization and extra spacing don’t matter.