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.

22.2 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>Pin Animation — Animation Handbook</title>
  <meta name="description" content="One part stays put while its text changes on scroll. Best for feature lists.">
  <link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/pin-animation/">
  <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="Pin Animation — Animation Handbook">
  <meta property="og:description" content="One part stays put while its text changes on scroll. Best for feature lists.">
  <meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/pin-animation/">
  <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="Pin Animation — Animation Handbook">
  <meta name="twitter:description" content="One part stays put while its text changes on scroll. Best for feature lists.">
  <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": "Pin Animation", "name": "Pin Animation", "description": "One part stays put while its text changes on scroll. Best for feature lists.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/01-scroll-based/pin-animation/", "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, Pin Animation"}</script>
  <style>
    :root{--ui-accent:#6ea8ff;--ui-border:rgba(255,255,255,.09);--ui-muted:#8a8a92}
    *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
    .stage{position:relative;overflow-y:auto;scrollbar-width:none;container-type:size;background:#0b0b0d}
    .stage::-webkit-scrollbar{display:none}
    /* Intro */
    .intro{height:100cqh;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;padding:32px;border-bottom:1px solid var(--ui-border)}
    .intro .panel-title{font-size:clamp(20px,3vw,28px);font-weight:700;margin-bottom:12px}
    .intro p:not(.panel-title){font-size:14px;color:var(--ui-muted);max-width:340px;line-height:1.65}
    /* Pin section: the extra height is how long the frame stays put */
    .pin-section{height:300cqh;position:relative}
    .pin-inner{position:sticky;top:0;height:100cqh;display:flex;align-items:center;justify-content:center;gap:32px;padding:32px}
    .phone-wrap{flex-shrink:0}
    .phone-wrap svg{height:min(200px,72cqh);width:auto}
    .copy-panel{flex:1;max-width:260px}
    .feat-num{font-size:11px;letter-spacing:2px;text-transform:uppercase;color:var(--ui-accent);margin-bottom:10px}
    .feat-title{font-size:clamp(18px,2.5vw,24px);font-weight:bold;margin-bottom:12px;line-height:1.2}
    .feat-desc{font-size:14px;color:var(--ui-muted);line-height:1.7}
    /* Outro */
    .outro{height:100cqh;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;padding:32px;border-top:1px solid var(--ui-border)}
    .outro .panel-title{font-size:clamp(18px,2.5vw,24px);font-weight:700;margin-bottom:10px}
    .outro p:not(.panel-title){font-size:14px;color:var(--ui-muted);max-width:300px;line-height:1.6}
    /* A layer fixed to the box (sticky and no taller than a line, at the top of the scroll content) holds what the two views
       draw over it. None of it is drawn in Normal. */
    .fx{position:sticky;top:0;height:0;z-index:5;display:none;pointer-events:none}
    .fx-box{position:absolute;left:0;top:0;width:100%;height:100cqh;overflow:hidden}
    .ruler,.name,.gone{display:none}
    .pin-inner.twin{display:none}
    /* See inside: the whole scroll as one ruler along the bottom of the box. Its parts are laid out from the measured section
       and box; a bright line stands where the box is, the step under it is lit and the steps passed stay half lit. */
    .stage[data-hb-mode="inside"] .fx,.stage[data-hb-mode="compare"] .fx{display:block}
    .stage[data-hb-mode="inside"] .ruler{display:block;position:absolute;left:8px;right:8px;bottom:6px;height:50px;overflow:hidden;
      border-radius:8px;background:rgba(11,11,13,.94);border:1px solid rgba(255,255,255,.22)}
    .track{position:absolute;left:8px;right:8px;top:5px;bottom:5px}
    .part{position:absolute;top:0;bottom:0}
    .part span{position:absolute;left:0;right:0;top:0;text-align:center;white-space:nowrap;color:#f4f4f2;font:600 12px/16px var(--hb-font)}
    .bar{position:absolute;left:1px;right:1px;bottom:5px;height:14px;display:flex;gap:2px}
    .bar i{flex:1;border-radius:3px;background:rgba(255,255,255,.34);opacity:.3}
    .part:nth-child(2) i:nth-child(1){background:#58a6ff}
    .part:nth-child(2) i:nth-child(2){background:#3fb950}
    .part:nth-child(2) i:nth-child(3){background:#bf91f3}
    .part:nth-child(2) i:nth-child(4){background:#ffa657}
    .bar i.past{opacity:.55}
    .bar i.on{opacity:1;outline:1px solid #fff;outline-offset:1px}
    .hx{position:absolute;left:0;top:0;width:100%;height:100%;will-change:transform}
    .hx b{position:absolute;left:-2px;top:19px;bottom:-1px;width:4px;border-radius:2px;background:#fff;box-shadow:0 0 0 1px rgba(11,11,13,.8)}
    .stage[data-hb-mode="inside"] .intro,.stage[data-hb-mode="inside"] .outro{padding-bottom:88px}
    .stage[data-hb-mode="inside"] .pin-inner{padding-bottom:88px}
    @media(min-width:601px){.stage[data-hb-mode="inside"] .phone-wrap svg{height:min(200px,calc(100cqh - 150px))}}
    @media(max-width:600px){.stage[data-hb-mode="inside"] .intro,.stage[data-hb-mode="inside"] .outro,.stage[data-hb-mode="inside"] .pin-inner{padding-bottom:72px}}
    /* Compare: the section becomes two columns. On the left a copy of the frame that is not sticky, so it leaves with the
       page; on the right the page's own frame, still sticky in its column. The intro and the outro are untouched. */
    /* The copy's title changes height, which scroll anchoring would answer by moving the box: it stays off in Compare */
    .stage[data-hb-mode="compare"]{overflow-anchor:none}
    .stage[data-hb-mode="compare"] .pin-section{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));grid-template-rows:minmax(0,1fr)}
    .stage[data-hb-mode="compare"] .pin-section::after{content:"";position:absolute;left:50%;top:0;bottom:0;width:1px;background:rgba(255,255,255,.45)}
    .stage[data-hb-mode="compare"] .pin-inner{align-self:start;flex-direction:column;gap:10px;padding:12px;text-align:center;min-width:0}
    .stage[data-hb-mode="compare"] .pin-inner.twin{display:flex;position:relative}
    .stage[data-hb-mode="compare"] .phone-wrap svg{height:min(150px,40cqh);width:auto}
    .stage[data-hb-mode="compare"] .copy-panel{flex:none;max-width:100%}
    .stage[data-hb-mode="compare"] .feat-desc{display:none}
    .stage[data-hb-mode="compare"] .feat-title{font-size:clamp(14px,2vw,18px);margin-bottom:0}
    .stage[data-hb-mode="compare"] .feat-num{margin-bottom:6px}
    .stage[data-hb-mode="compare"] .name{display:block;position:absolute;top:8px;padding:5px 10px;
      color:#f4f4f2;font:600 13px/1.2 var(--hb-font);white-space:nowrap}
    .n1{left:8px}.n2{left:calc(50% + 8px)}
    .gone svg{width:20px;height:20px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
    .stage[data-hb-mode="compare"] .gone.on{display:flex;flex-direction:column;align-items:center;gap:4px;position:absolute;left:8px;width:calc(50% - 16px);
      top:50%;transform:translateY(-50%);padding:8px 6px;border-radius:10px;background:rgba(11,11,13,.86);color:#f4f4f2;
      font:600 13px/1.2 var(--hb-font);text-align:center}
    @media(max-width:600px){.pin-inner{gap:14px;padding:16px}.phone-wrap svg{width:72px;height:131px}#phone-icon,.ph-title{display:none}}
  </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="../scrub-animation/" rel="prev" aria-label="Previous: Scrub Animation"><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>Scrub Animation</span></a><a href="../snap-scrolling/" rel="next" aria-label="Next: Snap Scrolling"><span><span class="hb-dir">Next: </span>Snap Scrolling</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.09 · Scroll-Based</p>
    <h1>Pin Animation</h1>
    <p class="hb-lede">One part stays put while its text changes on scroll. Best for feature lists.</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="A phone that holds still while its features change">
      <div class="fx" aria-hidden="true" inert>
        <div class="fx-box">
          <div class="ruler"><div class="track">
            <div class="part"><span data-hb-caption>Arrives</span><div class="bar"><i></i></div></div>
            <div class="part"><span data-hb-caption>Held: four equal steps</span><div class="bar"><i></i><i></i><i></i><i></i></div></div>
            <div class="part"><span data-hb-caption>Leaves</span><div class="bar"><i></i></div></div>
            <div class="hx"><b></b></div>
          </div></div>
          <span class="name n1" data-hb-caption>Not pinned</span>
          <span class="name n2" data-hb-caption>Pinned</span>
          <p class="gone" data-hb-caption><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 19V5M5 12l7-7 7 7"/></svg>Went up with the page</p>
        </div>
      </div>
      <div class="intro">
        <p class="panel-title">Scroll to begin</p>
        <p>The phone and its text will stop in the middle of the box and hold still while four features go by.</p>
      </div>
      <div class="pin-section" id="pin-section">
        <div class="pin-inner">
          <div class="phone-wrap">
            <svg width="110" height="200" viewBox="0 0 110 200" aria-hidden="true">
              <rect x="2" y="2" width="106" height="196" rx="16" fill="#1a1a2a" stroke="#3a3a5a" stroke-width="1.5"/>
              <rect id="phone-screen" x="9" y="18" width="92" height="152" rx="8" fill="#0d2b3e"/>
              <text id="phone-num" x="55" y="98" text-anchor="middle" font-size="28" font-weight="bold" fill="#58a6ff">01</text>
              <text id="phone-icon" class="ph-title" x="55" y="118" text-anchor="middle" font-size="11" fill="#c9d1d9">Instant Wake</text>
              <rect x="38" y="183" width="34" height="4" rx="2" fill="#3a3a5a"/>
            </svg>
          </div>
          <div class="copy-panel">
            <div class="feat-num" id="feat-num">01 / 04</div>
            <div class="feat-title" id="feat-title">Instant Wake</div>
            <div class="feat-desc" id="feat-desc">The display responds in under 1ms. Always on, never waiting. The sensor layer never sleeps.</div>
          </div>
        </div>
      </div>
      <div class="outro">
        <p class="panel-title">Pin released</p>
        <p>The phone and its text let go and scroll away with the page again.</p>
      </div>
    </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 bar is the whole scroll: the phone arrives, stays put through four equal steps, then leaves, and the line marks where you are. Scroll the box or press Play to watch.</p>
      <p data-hb-for="compare" hidden>Not pinned: the phone leaves with the page and empty space follows; Pinned: it holds still while the features change. 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 pinned section to [your product page, and the element that should stay in view]. Make the section several screens tall and pin the element and its text in the middle of the view while the visitor scrolls through it; the extra height is how long it stays. Split that distance into equal parts and show the next feature's text and picture in each part. When the section ends, let the element scroll away with the page. Use the browser's sticky positioning for the pin instead of moving it with a script. If the visitor has reduced motion turned on, change the features without animation.</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 page and element.</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>Feature lists</li><li>Product tours</li><li>Onboarding</li></ul>
      <h3>Avoid on</h3>
      <ul class="hb-tags hb-avoid"><li>Short screens</li><li>Long text</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 FEATURES=[
    {num:'01',title:'Instant Wake',              desc:'The display responds in under 1ms. Always on, never waiting. The sensor layer never sleeps.',              color:'#0d2b3e',tcolor:'#58a6ff'},
    {num:'02',title:'Computational Photography', desc:'Every frame processed by neural hardware in real time. Night mode renders before you lift the shutter.',   color:'#1e3a1e',tcolor:'#3fb950'},
    {num:'03',title:'On-Device Privacy',         desc:'Face recognition, transcription, translation — all local. No data leaves the device.',                     color:'#2d1b3d',tcolor:'#bf91f3'},
    {num:'04',title:'New Silicon Engine',        desc:'Unified memory architecture. The gap between laptop and phone performance has effectively closed.',         color:'#3d2000',tcolor:'#ffa657'},
  ];
  const stage=document.getElementById('stage'),pinSec=document.getElementById('pin-section');
  const featNum=document.getElementById('feat-num'),featTitle=document.getElementById('feat-title'),featDesc=document.getElementById('feat-desc');
  const phoneScreen=document.getElementById('phone-screen'),phoneNum=document.getElementById('phone-num'),phoneIcon=document.getElementById('phone-icon');
  let ticking=false,lastFi=-1;
  const clamp=(v,a,b)=>Math.min(Math.max(v,a),b);
  // Compare's left side: a copy of the frame that is not sticky, so it scrolls away with the page. It loses its ids (the
  // lines below keep what they need first), is inert and hidden from screen readers; the stage's name says what each half shows.
  const frame=pinSec.querySelector('.pin-inner'),twin=frame.cloneNode(true);
  const ref=id=>twin.querySelector('#'+id),T={num:ref('feat-num'),title:ref('feat-title'),desc:ref('feat-desc'),
    screen:ref('phone-screen'),pnum:ref('phone-num'),icon:ref('phone-icon')};
  twin.querySelectorAll('[id]').forEach(el=>el.removeAttribute('id'));
  twin.classList.add('twin');twin.inert=true;twin.setAttribute('aria-hidden','true');
  frame.before(twin);
  const LABELS={
    normal:'A phone that holds still while its features change',
    inside:'A phone that holds still while its features change, with a bar for the whole scroll and where it is held',
    compare:'The phone twice: scrolling away with the page, and held still while its features change',
  };
  const parts=[...stage.querySelectorAll('.part')],bars=[...stage.querySelectorAll('.bar i')],hx=stage.querySelector('.hx'),gone=stage.querySelector('.gone');
  let mode='normal',lastP=-1,lastGone=null;
  // The ruler's parts come from the measured section and box: the scroll before the hold, the hold, the scroll after it
  function layout(){
    const vh=stage.clientHeight,ps=pinSec.offsetTop,total=stage.scrollHeight-vh;
    if(total<=0)return;
    const a=ps/total,h=(pinSec.offsetHeight-vh)/total,at=[0,a,a+h],w=[a,h,1-a-h];
    parts.forEach((el,i)=>{el.style.left=at[i]*100+'%';el.style.width=w[i]*100+'%'});
  }
  function paint(){
    const st=stage.scrollTop,ps=pinSec.offsetTop,vh=stage.clientHeight,ph=pinSec.offsetHeight,total=stage.scrollHeight-vh;
    if(mode==='inside'&&total>0){
      hx.style.transform=`translateX(${clamp(st/total,0,1)*100}%)`;
      // 0 arrives, 1 to 4 the held steps, 5 leaves
      const p=st<ps?0:st>ps+ph-vh+.5?5:1+Math.min(3,Math.floor(clamp((st-ps)/(ph-vh),0,1)*4));
      if(p!==lastP){bars.forEach((b,i)=>{b.className=i===p?'on':i<p?'past':''});lastP=p}
    }
    if(mode==='compare'){
      // The copy has left the box above while the section still fills it
      const on=st>=ps+vh-24&&st<=ps+ph-vh;
      if(on!==lastGone){gone.classList.toggle('on',on);lastGone=on}
    }
  }
  function update(){
    // offsetTop and scrollTop are both measured from the stage's padding edge, so its border does not shift them
    const st=stage.scrollTop,ps=pinSec.offsetTop,ph=pinSec.offsetHeight,vh=stage.clientHeight;
    let fi=0;
    if(st>=ps+ph-vh)fi=3;
    else if(st>=ps)fi=Math.min(3,Math.floor(clamp((st-ps)/(ph-vh),0,1)*4));
    if(fi!==lastFi){
      const f=FEATURES[fi];
      featNum.textContent=`${f.num} / 04`;featTitle.textContent=f.title;featDesc.textContent=f.desc;
      phoneScreen.setAttribute('fill',f.color);phoneNum.setAttribute('fill',f.tcolor);phoneNum.textContent=f.num;
      // trim to the last whole word that still fits inside the 92px phone screen
      phoneIcon.textContent=f.title.length>16?f.title.slice(0,16).replace(/\s+\S*$/,'')+'…':f.title;
      phoneIcon.setAttribute('fill',f.tcolor);
      T.num.textContent=featNum.textContent;T.title.textContent=f.title;T.desc.textContent=f.desc;
      T.screen.setAttribute('fill',f.color);T.pnum.setAttribute('fill',f.tcolor);T.pnum.textContent=f.num;
      T.icon.textContent=phoneIcon.textContent;T.icon.setAttribute('fill',f.tcolor);
      lastFi=fi;
    }
    paint();
    ticking=false;
  }
  const schedule=()=>{if(!ticking){requestAnimationFrame(update);ticking=true}};
  // Draws the mode at once: the feature, the ruler and the message are written again for where the box stands
  document.addEventListener('hb:mode',e=>{
    mode=e.detail.mode;lastFi=-1;lastP=-1;lastGone=null;
    stage.setAttribute('aria-label',LABELS[mode]);
    layout();update();
  });
  stage.addEventListener('scroll',schedule,{passive:true});
  addEventListener('resize',()=>{layout();schedule()},{passive:true});
  update();
</script>
</body>
</html>