Skip to content

176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.

19.0 KB
Raw Blame
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Horizontal Scroll — Animation Handbook</title>
  <meta name="description" content="Scroll down and a row of panels slides sideways. Best for portfolios.">
  <link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/horizontal-scroll/">
  <link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
  <link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
  <link rel="apple-touch-icon" href="../../../apple-touch-icon.png">
  <meta property="og:type" content="article">
  <meta property="og:site_name" content="Animation Handbook">
  <meta property="og:title" content="Horizontal Scroll — Animation Handbook">
  <meta property="og:description" content="Scroll down and a row of panels slides sideways. Best for portfolios.">
  <meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/horizontal-scroll/">
  <meta property="og:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">
  <meta name="twitter:card" content="summary_large_image">
  <meta name="twitter:title" content="Horizontal Scroll — Animation Handbook">
  <meta name="twitter:description" content="Scroll down and a row of panels slides sideways. Best for portfolios.">
  <meta name="twitter:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">
  <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Horizontal Scroll", "name": "Horizontal Scroll", "description": "Scroll down and a row of panels slides sideways. Best for portfolios.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/horizontal-scroll/", "inLanguage": "en", "articleSection": "Scroll-Based", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Scroll-Based, Horizontal Scroll"}</script>
  <style>
    :root{--ui-accent:#6ea8ff;--panels:5}
    *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
    /* 100cqh is one stage height: the stage is the size container, so the pinned frame is exactly one box tall at every size */
    .stage{position:relative;overflow-y:auto;scrollbar-width:none;container-type:size;background:#0b0b0d}
    .stage::-webkit-scrollbar{display:none}
    /* Lead-in and lead-out */
    .spacer{height:60cqh;display:flex;align-items:center;justify-content:center;padding:0 24px;font-size:13px;color:#8a8a92;letter-spacing:.1em;text-align:center}
    /* The pin section is tall, to provide the scroll budget */
    #pin-section{height:calc(100cqh * var(--panels));position:relative}
    /* Sticky inner */
    #pin-inner{position:sticky;top:0;height:100cqh;overflow:hidden}
    /* Horizontal track */
    #h-track{display:flex;height:100%;will-change:transform;width:calc(var(--panels) * 100%)}
    .panel{flex:0 0 calc(100% / var(--panels));height:100%;display:flex;flex-direction:column;justify-content:center;padding:clamp(24px,4vw,48px);background:var(--bg)}
    .panel-num{font-size:clamp(48px,6vw,80px);font-weight:700;opacity:.1;line-height:1;margin-bottom:12px}
    .panel-title{font-size:clamp(22px,2.4vw,32px);font-weight:700;line-height:1.2;margin-bottom:14px;color:var(--ac)}
    .panel-body{font-size:clamp(14px,1.2vw,16px);line-height:1.6;color:#d6d6da;max-width:480px}
    /* The layer for both views is fixed to the box: sticky at the top of the stage and no tall, so it adds nothing to the scroll */
    .fx{display:none;position:sticky;top:0;height:0;z-index:6;pointer-events:none}
    .fx-in,.fx-cmp,.stack{display:none}
    .stage[data-hb-mode="inside"] .fx,.stage[data-hb-mode="compare"] .fx{display:block}
    .fx-in,.fx-cmp{position:absolute;left:0;top:0;width:100cqw;height:100cqh}
    .cap{position:absolute;padding:3px 7px;border-radius:999px;white-space:nowrap;background:rgba(11,11,13,.92);color:#f4f4f2;
      font:600 12px/1.25 var(--hb-font)}
    /* See inside: a map of the whole strip along the bottom, a frame on it for what the box shows, and a bar for the whole
       scroll down the right edge. The frame and the marker are moved by the page's own update. The map shrinks the strip's
       slide, so a faint dashed frame stays on the first tile, where the frame started (ruling 2). */
    .stage[data-hb-mode="inside"] .fx-in{display:block}
    .stage[data-hb-mode="inside"] #h-track{opacity:.45}
    .map{position:absolute;left:10px;right:10px;bottom:30px;height:44px;display:flex;padding:4px;border-radius:8px;background:rgba(11,11,13,.92)}
    .tile{flex:1 1 0;display:flex;align-items:center;justify-content:center;background:var(--ac);color:#0b0b0d;font:700 13px/1 var(--hb-font)}
    .mstart,.mframe{position:absolute;left:4px;top:4px;bottom:4px;width:calc((100% - 8px) / var(--panels))}
    .mstart{border:2px dashed rgba(244,244,242,.75)}
    .mframe{border:3px solid #fff;box-shadow:0 0 0 2px #0b0b0d,inset 0 0 0 2px #0b0b0d}
    .mframe .cap{top:calc(100% + 9px);left:50%;translate:-50% 0;border:1px solid #fff}
    .cap-map{left:10px;bottom:80px}
    .bar-wrap{position:absolute;right:10px;top:12px;bottom:112px;width:16px;padding:3px;border-radius:8px;background:rgba(11,11,13,.92)}
    .bar{display:flex;flex-direction:column;height:100%;border-radius:5px;overflow:hidden}
    .bar span{flex:1 1 0;min-height:0;background:#8a8a92}
    .bar span:nth-child(2){background:var(--ui-accent)}
    .mk{position:absolute;left:50%;top:3px;width:28px;height:5px;margin-left:-14px;border-radius:3px;background:#fff;box-shadow:0 0 0 2px #0b0b0d}
    .cap-bar{right:34px;top:14px}
    /* Compare: a column of the panels one above the other, an ordinary scroll, beside the page itself in the right half. The
       column is out of the flow and exactly as tall as the real content, so the scroll never changes; its panels start half a
       box lower, so the halves never show the same whole panel at once. */
    .stage[data-hb-mode="compare"] .fx-cmp{display:block}
    .stage[data-hb-mode="compare"] .stack{display:block;position:absolute;top:0;left:0;width:50cqw;
      height:calc(var(--panels) * 100cqh + 119.9cqh)}
    .stack .spacer{margin-bottom:50cqh}
    .stack .panel{height:100cqh}
    .stage[data-hb-mode="compare"]>.spacer,.stage[data-hb-mode="compare"]>#pin-section{margin-left:50cqw}
    /* The number and title sit at the top of each panel, so a panel half out of the box still shows what it is, clear of the names */
    .stage[data-hb-mode="compare"] .panel{justify-content:flex-start;padding:clamp(40px,13cqh,56px) clamp(14px,3vw,40px) 0}
    .stage[data-hb-mode="compare"] .panel-num{font-size:clamp(32px,4.4vw,72px);margin-bottom:8px}
    .stage[data-hb-mode="compare"] .panel-title{font-size:clamp(17px,2.2vw,30px);margin-bottom:0}
    .stage[data-hb-mode="compare"] .panel-body{display:none}
    .split{position:absolute;left:50cqw;top:0;bottom:0;width:2px;margin-left:-1px;background:#0b0b0d}
    .cap-l{left:8px;top:8px}
    .cap-r{left:calc(50cqw + 8px);top:8px}
  </style>
  <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=11">
  <script src="../../../assets/js/demo-page.js?v=11" defer></script>
</head>
<body class="hb" data-hb-kind="scroll" data-hb-autoplay>
<nav class="hb-bar" aria-label="Animation Handbook">
  <a class="hb-home" href="../../../"><svg class="hb-mark" viewBox="0 0 32 32" aria-hidden="true"><g class="g"><circle cx="11.16" cy="20.84" r="6.1"/><circle cx="15.12" cy="16.88" r="6.1"/><circle cx="18.51" cy="13.49" r="6.1"/></g><circle class="b" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>
  <span class="hb-pager"><a href="../stagger-reveal/" rel="prev" aria-label="Previous: Stagger Reveal"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg><span><span class="hb-dir">Previous: </span>Stagger Reveal</span></a><a href="../sticky-section/" rel="next" aria-label="Next: Sticky Section"><span><span class="hb-dir">Next: </span>Sticky Section</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg></a></span>
  <a class="hb-star" href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener" aria-label="Star on GitHub"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3l2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z"/></svg><span>Star on GitHub</span></a>
</nav>
<main class="hb-page">
  <header class="hb-head">
    <p class="hb-cat">01.14 · Scroll-Based</p>
    <h1>Horizontal Scroll</h1>
    <p class="hb-lede">Scroll down and a row of panels slides sideways. Best for portfolios.</p>
  </header>

  <section class="hb-step hb-watch" aria-labelledby="hb-watch-title">
    <div class="hb-step-head">
      <span class="hb-num" aria-hidden="true">1</span>
      <div><h2 id="hb-watch-title">Scroll it</h2><p>Scroll inside the box, or press Play and it scrolls for you.</p></div>
    </div>
    <div class="seg hb-modes" role="group" aria-label="What the box shows" data-hb-modes>
      <button type="button" data-hb-mode="normal" class="on" aria-pressed="true">Normal</button>
      <button type="button" data-hb-mode="inside" aria-pressed="false">See inside</button>
      <button type="button" data-hb-mode="compare" aria-pressed="false">Compare</button>
    </div>
    <div class="stage" id="stage" tabindex="0" role="region" aria-label="Panels that slide sideways as you scroll">
      <div class="fx">
        <div class="fx-in">
          <div class="bar-wrap"><div class="bar"><span></span><span></span><span></span></div><i class="mk"></i></div>
          <p class="cap cap-bar" data-hb-caption>You scroll down</p>
          <p class="cap cap-map" data-hb-caption>The whole strip</p>
          <div class="map"><i class="mstart"></i><i class="mframe"><b class="cap" data-hb-caption>In the box</b></i></div>
        </div>
        <div class="fx-cmp">
          <i class="split"></i>
          <p class="cap cap-l" data-hb-caption>Stacked ↑</p>
          <p class="cap cap-r" data-hb-caption>Slides sideways ←</p>
        </div>
      </div>
      <p class="spacer">Scroll down ↓</p>
      <div id="pin-section">
        <div id="pin-inner">
          <div id="h-track">
            <div class="panel" style="--bg:linear-gradient(135deg,#0d2b3e,#1a3a5c);--ac:#79c0ff">
              <div class="panel-num" aria-hidden="true">01</div>
              <div class="panel-title">Scroll down, move sideways</div>
              <div class="panel-body">The panels sit side by side in one long strip. As you scroll down, the strip slides left, one panel at a time.</div>
            </div>
            <div class="panel" style="--bg:linear-gradient(135deg,#2d1b3d,#3d2a5c);--ac:#d2a8ff">
              <div class="panel-num" aria-hidden="true">02</div>
              <div class="panel-title">The box holds still</div>
              <div class="panel-body">While the strip slides, the section around it stays pinned in place, so the page seems to pause.</div>
            </div>
            <div class="panel" style="--bg:linear-gradient(135deg,#1e3a1e,#2d5c2d);--ac:#56d364">
              <div class="panel-num" aria-hidden="true">03</div>
              <div class="panel-title">Your scroll does the work</div>
              <div class="panel-body">There is no sideways scrolling to learn. The ordinary scroll you already use moves everything.</div>
            </div>
            <div class="panel" style="--bg:linear-gradient(135deg,#3d2000,#5c3400);--ac:#ffa657">
              <div class="panel-num" aria-hidden="true">04</div>
              <div class="panel-title">Scroll back, it slides back</div>
              <div class="panel-body">The strip follows your scroll exactly, so scrolling up brings the earlier panels back.</div>
            </div>
            <div class="panel" style="--bg:linear-gradient(135deg,#1a3a3a,#2a5c5c);--ac:#a5d6ff">
              <div class="panel-num" aria-hidden="true">05</div>
              <div class="panel-title">Then the page moves on</div>
              <div class="panel-body">Once the last panel is in view, the section lets go and the page scrolls on as normal.</div>
            </div>
          </div>
        </div>
      </div>
      <p class="spacer">The page moves on ↓</p>
    </div>
    <div class="hb-player">
      <button class="hb-play" type="button" id="btn-scroll" data-hb-autoscroll><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M19 12l-7 7-7-7"/></svg>Play</button>
      <button class="hb-play" type="button" id="btn-top" data-hb-top><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 19V5M5 12l7-7 7 7"/></svg>Back to top</button>
    </div>
    <div class="hb-mode-notes" aria-live="polite">
      <p data-hb-for="inside" hidden>Inside, the map is the whole strip of five panels, the bright frame is the box, and the side bar is how far you scrolled. Scroll the box or press Play to watch.</p>
      <p data-hb-for="compare" hidden>Stacked scrolls its panels up the ordinary way; Slides sideways holds the box still and brings each panel in from the right as you scroll down. Scroll the box or press Play to watch.</p>
    </div>
  </section>

  <section class="hb-step hb-prompt-step" aria-labelledby="hb-prompt-title">
    <div class="hb-step-head">
      <span class="hb-num" aria-hidden="true">2</span>
      <div><h2 id="hb-prompt-title">Copy the prompt</h2><p>Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.</p></div>
    </div>
    <div class="hb-card">
      <p class="hb-prompt">Add a horizontal scroll section to [the panels or projects you want to show]. Place the panels side by side in one long strip inside a section that is several screens tall. As the visitor scrolls down through that section, pin its inner frame in place and slide the strip to the left in step with the scroll, so scrolling down moves the panels sideways; once the last panel is in view, release the frame and let the page scroll on. Give the strip an explicit width so it can move. Keep the visitor's own scrolling, touch included, so scrolling back up slides the panels back. If the visitor has reduced motion turned on, keep the strip tied exactly to their scrolling, with no easing or snapping added.</p>
      <div class="hb-chips-box" hidden>
        <p class="hb-chips-title">Your settings</p>
        <ul class="hb-chips"></ul>
      </div>
      <div class="hb-copy-row">
        <button class="hb-copy" type="button"><svg class="hb-ic hb-i-copy" viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg><svg class="hb-ic hb-i-done" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg><span class="hb-copy-label" aria-live="polite">Copy prompt</span></button>
        <p class="hb-hint">Replace the words in brackets with your own panels.</p>
      </div>
    </div>
    <div class="hb-star-row"><p>Free and open source. If this helped, a star on GitHub helps other people find it.</p><a class="hb-star-btn" href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3l2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z"/></svg>Star on GitHub</a></div>
  </section>

  <section class="hb-about" aria-labelledby="hb-what-title">
    <div class="hb-what">
      <h2 id="hb-what-title">What it is</h2>
      <div class="hb-what-text"><p>The full explanation is in <a href="README.md">README.md</a>.</p></div>
    </div>
    <div class="hb-fit">
      <h2>Good for</h2>
      <ul class="hb-tags hb-good"><li>Portfolios</li><li>Timelines</li><li>Product features</li><li>Step-by-step tours</li></ul>
      <h3>Avoid on</h3>
      <ul class="hb-tags hb-avoid"><li>Long text</li><li>Forms</li></ul>
    </div>
  </section>

  <section class="hb-related" aria-labelledby="hb-related-title" hidden>
    <h2 id="hb-related-title">Similar animations</h2>
    <div class="hb-rel-list"></div>
  </section>
</main>
<footer class="hb-foot"><span>Animation Handbook</span><a href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener">Source on GitHub</a><a href="#top">Back to top ↑</a></footer>
<script>
  const stage=document.getElementById('stage'),track=document.getElementById('h-track'),pinSection=document.getElementById('pin-section');
  const pinInner=document.getElementById('pin-inner'),panels=[...track.children];
  let ticking=false,mode='normal';
  const clamp=(v,a,b)=>Math.min(Math.max(v,a),b);
  const LABELS={
    normal:'Panels that slide sideways as you scroll',
    inside:'Panels that slide sideways as you scroll, with a map of the whole strip and a bar for your scroll',
    compare:'The panels twice: stacked and scrolling up, and in a strip that slides sideways'
  };

  // The views' parts, made once from the panels: the map's tiles and, for Compare, an inert column of copies without ids
  const map=stage.querySelector('.map'),frame=stage.querySelector('.mframe'),marker=stage.querySelector('.mk');
  const bar=stage.querySelector('.bar'),parts=bar.children;
  map.prepend(...panels.map(p=>{
    const t=document.createElement('span');
    t.className='tile';t.setAttribute('style',p.getAttribute('style'));t.setAttribute('aria-hidden','true');
    t.textContent=p.querySelector('.panel-num').textContent;
    return t;
  }));
  const stack=document.createElement('div');
  stack.className='stack';stack.inert=true;stack.setAttribute('aria-hidden','true');
  stack.append(stage.querySelector('.spacer').cloneNode(true),...panels.map(p=>p.cloneNode(true)));
  stage.querySelector('.fx').after(stack);

  function update(){
    const budget=pinSection.offsetHeight-stage.clientHeight;
    const progress=clamp((stage.scrollTop-pinSection.offsetTop)/budget,0,1);
    // The frame's own width: the stage's in Normal, half of it in Compare
    const maxShift=track.offsetWidth-pinInner.clientWidth;
    track.style.transform=`translateX(${(-progress*maxShift).toFixed(2)}px)`;
    if(mode==='inside'){
      // The frame rides the map by the same share; the bar's three parts are the lead-in, the held section and the lead-out
      const max=stage.scrollHeight-stage.clientHeight,lead=pinSection.offsetTop;
      frame.style.transform=`translateX(${(progress*(panels.length-1)*100).toFixed(2)}%)`;
      parts[0].style.flexGrow=lead;parts[1].style.flexGrow=budget;parts[2].style.flexGrow=Math.max(max-lead-budget,0);
      marker.style.transform=`translateY(${((max>0?stage.scrollTop/max:0)*(bar.clientHeight-marker.offsetHeight)).toFixed(2)}px)`;
    }
    ticking=false;
  }
  function schedule(){if(!ticking){requestAnimationFrame(update);ticking=true}}

  document.addEventListener('hb:mode',e=>{
    mode=e.detail.mode;
    stage.setAttribute('aria-label',LABELS[mode]);
    update();
  });
  stage.addEventListener('scroll',schedule,{passive:true});
  window.addEventListener('resize',schedule);
  update();
</script>
</body>
</html>