All effectsClick & switch

Click-Through Carousel

手动轮播

Previous and next controls slide a sequence to the chosen item.

Switch slides with the arrows

Where to use it

Browse a small collection of featured images or product views. Let viewers advance at their own pace when each item has details worth examining.

Practical example

On a tent product page the customer presses Next to slide from the packed-bag photo to a close-up of the rainfly. The frame stays in place as they move through the photos.

AI prompt

Build a manual Carousel for [items]. Keep one slide in the viewport, update the position on previous or next, and keep active controls keyboard accessible. Announce the slide number when it changes.

Example code

Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.

View HTML
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Click-Through Carousel</title>
  <style>
    :root {
      color-scheme: dark;
      --demo-bg: #171629;
      --demo-ink: #f8f5ff;
      --demo-accent: #b9a6ff;
      --demo-muted: #bfbbd3;
      font-family: system-ui, sans-serif;
      color: var(--demo-ink);
      background: var(--demo-bg);
    }

    *, *::before, *::after { box-sizing: border-box; }
    body { margin: 0; min-width: 0; }
    button, input { font: inherit; }

    .demo {
      display: grid;
      place-items: center;
      align-content: center;
      min-height: 100vh;
      padding: 14px;
      overflow: hidden;
      background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
    }

    .demo-button {
      border: 1px solid #ffffff3d;
      border-radius: 7px;
      background: #ffffff12;
      color: var(--demo-ink);
      padding: 6px 11px;
      font-size: 12px;
      cursor: pointer;
    }

    :focus-visible {
      outline: 2px solid var(--demo-accent);
      outline-offset: 3px;
    }

    .example { width: min(100%, 228px); position: relative; display: grid; gap: 10px; }
    .panel { background: #292240; border: 1px solid #675785; border-radius: 11px; padding: 10px; }
    .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
    .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
    .label { margin: 0; font-size: 13px; font-weight: 650; }
    .detail, .caption { margin: 0; color: #d7cbea; font-size: 11px; line-height: 1.35; }
    .caption { text-align: center; }
    .control { border: 1px solid #8874ae; background: #392e57; border-radius: 7px; padding: 5px 9px; min-height: 32px; color: #f6efff; cursor: pointer; font-size: 11px; font-weight: 650; }
    .control:hover { background: #514174; }
    .control.primary { color: #261b3f; background: #d1bfff; border-color: #e3d8ff; }
    .control.primary:hover { background: #e3d8ff; }
    .control:disabled { opacity: .55; cursor: default; }
    .field { width: 100%; min-width: 0; padding: 6px 8px; border: 1px solid #875fa8; border-radius: 6px; color: #f6efff; background: #1e1732; font-size: 12px; }
    .field::placeholder { color: #c2abd8; }
    [hidden] { display: none !important; }

    .carousel { overflow: hidden; border-radius: 8px; }
    .slides { display: flex; transition: transform .28s ease; }
    .slide { flex: 0 0 100%; display: grid; place-items: center; height: 76px; color: #332240; font-weight: 740; }
    .slide-0 { background: #dfc0fb; }
    .slide-1 { background: #a9e3d9; }
    .slide-2 { background: #ffc5a5; }
    .slide-count { display: grid; place-items: center; padding-inline: 5px; font-size: 11px; }

    @media (prefers-reduced-motion: reduce) {
      .example *, .example *::before, .example *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
    }
  </style>
</head>
<body>
  <main class="demo">
    <div class="example"><div class="carousel" aria-label="Color collection"><div class="slides"><div class="slide slide-0" aria-hidden="false">Orchid</div><div class="slide slide-1" aria-hidden="true">Lagoon</div><div class="slide slide-2" aria-hidden="true">Sunset</div></div></div><div class="actions"><button class="control" type="button" aria-label="Previous" data-prev>‹</button><output class="slide-count" aria-live="polite">1 / 3</output><button class="control" type="button" aria-label="Next" data-next>›</button></div></div>
  </main>
  <script>
    const track = document.querySelector('.slides');
    const slides = Array.from(track.children);
    const status = document.querySelector('.slide-count');
    let index = 0;
    function move(by) {
      index = (index + by + slides.length) % slides.length;
      track.style.transform = 'translateX(' + (-100 * index) + '%)';
      status.value = (index + 1) + ' / ' + slides.length;
      slides.forEach((slide, position) => slide.setAttribute('aria-hidden', String(position !== index)));
    }
    document.querySelector('[data-prev]').addEventListener('click', () => move(-1));
    document.querySelector('[data-next]').addEventListener('click', () => move(1));
  </script>
</body>
</html>

Original example by UI Skills