Draggable Carousel Sliders With Momentum

Updated 2026-10-16. 12 effects.

A draggable carousel slider follows the finger or mouse as you pull it, keeps gliding after release at the speed you let go, then settles on the nearest slide. Pointer events with setPointerCapture handle the drag, a short frame loop applies friction, and buttons and arrow keys move one slide at a time.

Start from what people do with the content. Browsing a range of products or case studies suits a free rail that coasts and lands on a card, because people skim and stop where something catches their eye. Telling a short sequence, such as rooms of a flat or quotes from clients, suits one slide at a time with a counter, where each push moves exactly one place.

Dragging is a bonus, never the only way through. Every slider here has visible previous and next buttons, answers the left and right arrow keys once it has focus, and announces the new slide politely to screen readers. On phones the track only claims sideways swipes, so a vertical swipe still scrolls the page.

If you only need a row that snaps under the thumb with no physics at all, a scroll-snap carousel is simpler and lighter; the image carousel and the snap rows linked below cover that. The object-style carousels in the gallery, such as the slide projector and the postcard rack, are crafted showpieces rather than general sliders.

Compare them

EffectBuilt withSize (gzipped)Running costBrowser support
Canvas Tile Image Transition Drag SliderCanvas 2D3.7 KBThe canvas paints forty tiles only during a change of under a second, then a plain image takes over.All current browsers; plain image swap if the canvas cannot draw
Cover Flow Record Slider With Centre FocusCSS and a small script3.8 KBEach frame of a drag writes one transform per sleeve, seven in this demo, all on composited layers, and nothing runs at rest.All current browsers
Flick Away Stacked Card Deck SliderCSS and a small script3.4 KBOnly the top two cards are written each frame while dragging or flying, and the loop ends as soon as the deck settles.All current browsers
Free Scroll Plant Strip That Coasts Then SpringsCSS and a small script4.1 KBA single translate3d plus an opacity class swap per frame, and the loop ends as soon as the spring comes to rest.All current browsers
Full Bleed Hero Slider With Parallax PhotosCSS and a small script3.8 KBTwo transforms per slide in view are written each frame of a drag or settle; at rest the script does nothing.All current browsers
Main Slide With Synced Draggable Thumbnail StripCSS and a small script3.6 KBTwo rails share one short physics routine and each runs a frame loop only while it is moving.All current browsers
Masked Strip Photo Transition Drag SliderCSS and a small script3.6 KBStrips move with CSS transform transitions on their own layers; the script only runs while the rail is dragged or settling.All current browsers
Momentum Card Rail With Progress BarCSS and a small script4.1 KBOne transform on the track and one scaleX on the bar, written once per frame only while a drag or settle is running.All current browsers
Slider With Draggable Scrubber HandleCSS and a small script3.9 KBTwo transforms, one for the track and one for the handle, are written once per frame during a drag or settle and never at rest.All current browsers
Testimonial Slider With Big Quote and DragCSS and a small script3.8 KBPer frame it writes one track transform plus an opacity and transform for each of the four quotes, and only while moving.All current browsers
Two Linked Drag Rails Moving at Different SpeedsCSS and a small script3.3 KBTwo transforms per frame from one shared position, written only while dragging or settling.All current browsers
Vertical Drag Menu Slider Inside a Phone MockupCSS and a small script3.3 KBOne transform on the screen's track per frame, only while a finger is down or the screen is settling.All current browsers

Canvas Tile Image Transition Drag Slider

A pottery studio's year told in five photos, with a numbered caption list under the picture. Pulling the photo or the list sideways moves the captions with momentum, and every time a new caption lands the photo breaks into a grid of tiles that slide and fade into the next shot. Suits a portfolio or process story with a handful of strong images.

<section class="w2til" role="region" aria-roledescription="carousel" aria-label="Ondra Clay Studio work">
  <div class="w2til-wrap">
    <div class="w2til-head">
      <div>
        <p class="w2til-kicker">Ondra Clay Studio</p>
        <h2 class="w2til-title">A year in the studio</h2>
      </div>
      <p class="w2til-copy">Drag the photo or the list, or use the arrows. Each change breaks the picture into tiles that slide into the next one.</p>
    </div>
    <div class="w2til-stage" tabindex="0">
      <img class="w2til-img w2til-on" src="https://images.pexels.com/photos/31875677/pexels-photo-31875677.jpeg?auto=compress&cs=tinysrgb&w=1400" alt="Hands shaping a clay pot on a spinning pottery wheel" draggable="false">
      <img class="w2til-img" src="https://images.pexels.com/photos/33703946/pexels-photo-33703946.jpeg?auto=compress&cs=tinysrgb&w=1400" alt="Stacks of unglazed clay bowls on wooden shelves" draggable="false" aria-hidden="true">
      <img class="w2til-img" src="https://images.pexels.com/photos/7119222/pexels-photo-7119222.jpeg?auto=compress&cs=tinysrgb&w=1400" alt="Two stoneware vases with dotted texture against a rust wall" draggable="false" aria-hidden="true">
      <img class="w2til-img" src="https://images.pexels.com/photos/8063852/pexels-photo-8063852.jpeg?auto=compress&cs=tinysrgb&w=1400" alt="Glazed bud vases in red, grey and cream on a table" draggable="false" aria-hidden="true">
      <img class="w2til-img" src="https://images.pexels.com/photos/8063803/pexels-photo-8063803.jpeg?auto=compress&cs=tinysrgb&w=1400" alt="Rows of unglazed white mugs on a studio shelf" draggable="false" aria-hidden="true">
      <canvas class="w2til-cv" aria-hidden="true"></canvas>
    </div>
    <div class="w2til-bar">
      <div class="w2til-view">
        <ol class="w2til-track">
          <li class="w2til-item w2til-on" role="group" aria-roledescription="slide" aria-label="1 of 5"><span class="w2til-num">01</span><span class="w2til-name">Throwing on the wheel</span><span class="w2til-sub">Tuesday evening class</span></li>
          <li class="w2til-item" role="group" aria-roledescription="slide" aria-label="2 of 5"><span class="w2til-num">02</span><span class="w2til-name">Bowls on the drying rack</span><span class="w2til-sub">Red earthenware</span></li>
          <li class="w2til-item" role="group" aria-roledescription="slide" aria-label="3 of 5"><span class="w2til-num">03</span><span class="w2til-name">Dotted stoneware vases</span><span class="w2til-sub">Pressed by hand</span></li>
          <li class="w2til-item" role="group" aria-roledescription="slide" aria-label="4 of 5"><span class="w2til-num">04</span><span class="w2til-name">Glazed bud vases</span><span class="w2til-sub">Iron red and celadon</span></li>
          <li class="w2til-item" role="group" aria-roledescription="slide" aria-label="5 of 5"><span class="w2til-num">05</span><span class="w2til-name">Mugs waiting for glaze</span><span class="w2til-sub">Bisque fired</span></li>
        </ol>
      </div>
      <div class="w2til-btns">
        <button class="w2til-btn" type="button" data-d="-1" disabled aria-label="Previous slide"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M15 5l-7 7 7 7" fill="none" stroke="currentColor" stroke-width="2"/></svg></button>
        <button class="w2til-btn" type="button" data-d="1" aria-label="Next slide"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M9 5l7 7-7 7" fill="none" stroke="currentColor" stroke-width="2"/></svg></button>
      </div>
    </div>
    <p class="w2til-live" aria-live="polite"></p>
  </div>
</section>
<style>
  /* Change these: paper colour, ink colour, accent, list item width. */
  .w2til { --w2til-bg: #f3ece2; --w2til-ink: #2b211b; --w2til-acc: #a4502f; --w2til-item: 230px; }
  .w2til { background: var(--w2til-bg); color: var(--w2til-ink); padding: 48px 16px; font-family: ui-sans-serif, system-ui, sans-serif; overflow: hidden; }
  .w2til-wrap { max-width: 980px; margin: 0 auto; }
  .w2til-head { display: flex; flex-wrap: wrap; gap: 16px 48px; align-items: flex-end; justify-content: space-between; margin-bottom: 28px; }
  .w2til-kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .24em; text-transform: uppercase; color: var(--w2til-acc); }
  .w2til-title { margin: 10px 0 0; font: 600 clamp(28px, 4vw, 42px)/1.12 Georgia, "Times New Roman", serif; letter-spacing: -.01em; max-width: 16em; }
  .w2til-copy { margin: 0; max-width: 24rem; font-size: 15px; line-height: 1.6; color: #5b4c41; }
  .w2til-stage { position: relative; aspect-ratio: 11 / 5; border-radius: 14px; overflow: hidden; background: #d9cbb9; touch-action: pan-y; cursor: grab; box-shadow: 0 24px 48px -28px rgba(60, 35, 20, .45); user-select: none; }
  .w2til-img, .w2til-cv { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; }
  .w2til-img.w2til-on { opacity: 1; }
  .w2til-cv.w2til-on { opacity: 1; }
  .w2til-bar { display: flex; align-items: center; gap: 16px; margin-top: 22px; }
  .w2til-view { flex: 1; min-width: 0; overflow: hidden; touch-action: pan-y; cursor: grab; }
  .w2til-track { display: flex; margin: 0; padding: 0; list-style: none; will-change: transform; }
  .w2til-item { flex: 0 0 var(--w2til-item); padding: 14px 18px 4px 0; border-top: 2px solid rgba(43, 33, 27, .14); opacity: .5; transition: opacity .3s, border-color .3s; user-select: none; }
  .w2til-item.w2til-on { opacity: 1; border-color: var(--w2til-acc); }
  .w2til-num { display: block; font-size: 12px; font-weight: 700; color: var(--w2til-acc); }
  .w2til-name { display: block; margin-top: 4px; font-size: 16px; font-weight: 600; }
  .w2til-sub { display: block; margin-top: 2px; font-size: 13px; color: #5b4c41; }
  .w2til-btns { display: flex; gap: 8px; }
  .w2til-btn { width: 46px; height: 46px; border-radius: 50%; border: 1px solid rgba(43, 33, 27, .25); background: #fffaf3; color: var(--w2til-ink); display: grid; place-items: center; cursor: pointer; }
  .w2til-btn:hover { background: #fff; }
  .w2til-btn:disabled { opacity: .35; cursor: default; }
  .w2til-btn:focus-visible, .w2til-stage:focus-visible { outline: 2px solid var(--w2til-acc); outline-offset: 3px; }
  .w2til-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  @media (max-width: 640px) { .w2til-stage { aspect-ratio: 4 / 3; } }
  @media (prefers-reduced-motion: reduce) { .w2til-item { transition: none; } }
</style>
<script>
(function(){
/* Change these: tile grid, change length in ms, friction per frame, idle advance in ms. */
var COLS=8,ROWS=5,DUR=700,FRICTION=.93,IDLE=3000;
var R=document.querySelector(".w2til");
var Q=function(s){return R.querySelectorAll(s)},O="w2til-on",T=function(e,b){e.classList.toggle(O,b)},M=Math,F=requestAnimationFrame;
var st=Q(".w2til-stage")[0],tr=Q(".w2til-track")[0],cv=Q(".w2til-cv")[0],im=Q(".w2til-img"),it=Q(".w2til-item"),bt=Q(".w2til-btn"),lv=Q(".w2til-live")[0];
var n=it.length,rm=matchMedia("(prefers-reduced-motion: reduce)").matches,c2=cv.getContext("2d");
var x=0,v=0,tx=0,raf=0,dn=0,sx,x0,H,I=0,sh=0,t0,fr,dir,tl=0,V=1,au=0,w,h,d;
function cl(i){return M.max(0,M.min(n-1,i))}
function show(i){if(i==I)return;dir=i>I?1:-1;fr=sh;I=i;
it.forEach(function(e,k){T(e,k==i)});bt[0].disabled=!i;bt[1].disabled=i==n-1;
if(rm||!c2||!(im[fr].naturalWidth*im[i].naturalWidth))return swap();w=st.clientWidth;h=st.clientHeight;d=M.min(devicePixelRatio||1,2);cv.width=w*d;cv.height=h*d;c2.scale(d,d);T(im[fr],0);t0=0;tl=tl||F(draw)}
function swap(){im.forEach(function(e,k){T(e,k==I);e.ariaHidden=k!=I});sh=I;T(cv,0)}
function cell(g,c,r,o,a){var u=g.naturalWidth,y=g.naturalHeight,s=M.max(w/u,h/y),q=w/COLS,z=h/ROWS;c2.globalAlpha=a;
c2.drawImage(g,(u-w/s)/2+c*q/s,(y-h/s)/2+r*z/s,q/s,z/s,c*q+o,r*z,q+.5,z+.5)}
function draw(now){tl=0;t0=t0||now;if(!V)return swap();
var p=M.min((now-t0)/DUR,1)*1.05,c,r;
c2.clearRect(0,0,w,h);T(cv,1);
for(c=0;c<COLS;c++)for(r=0;r<ROWS;r++){
/* each tile starts a little later across the sweep, slides sideways and crossfades */
var t=M.max(0,M.min(1,(p-(dir>0?c:COLS-1-c)/COLS*.5-r/ROWS*.15)/.4)),o=w/COLS*.45*dir;t=t*t*(3-2*t);
cell(im[fr],c,r,-o*t,1-t);cell(im[I],c,r,o*(1-t),t)}
p<1.05?tl=F(draw):swap()}
function loop(){raf=0;var s=it[0].offsetWidth,m=-(n-1)*s,g,p;
if(!dn){if(tx==null){x+=v;v*=FRICTION;if(x>0||x<m)v*=.6;if(M.abs(v)<.5)tx=cl(M.round(-x/s))}
if(tx!=null){g=-tx*s;x=rm?g:x+(g-x)*.16;if(M.abs(g-x)<.5)x=g}}
p=x>0?x*.3:x<m?m+(x-m)*.3:x;tr.style.transform="translate3d("+p+"px,0,0)";show(cl(M.round(-p/s)));
if(V&&(dn||tx==null||x!=-tx*s))raf=F(loop)}
function k(){raf=raf||F(loop)}
function go(i,say){tx=cl(i);v=0;k();if(say)lv.textContent="Slide "+(tx+1)+": "+it[tx].children[1].textContent}
function S(){clearTimeout(au);au=-1}
function up(e){if(!dn)return;dn=0;if(rm||e.timeStamp-H>100)v=0;tx=null;k()}
[st,tr.parentNode].forEach(function(el){
el.onpointerdown=function(e){S();dn=1;sx=e.clientX;x0=x;v=0;el.setPointerCapture(e.pointerId);k()};
el.onpointermove=function(e){if(!dn)return;var d=e.clientX-sx;v=v*.5+(x0+d-x)*.5;x=x0+d;H=e.timeStamp;k()};
el.onpointerup=el.onpointercancel=up;});
bt.forEach(function(b){b.onclick=function(){S();go(I+ +b.dataset.d,1)}});
R.onkeydown=function(e){var i={ArrowLeft:I-1,ArrowRight:I+1}[e.key];if(i!=null){e.preventDefault();S();go(i,1)}};
R.onpointerenter=S;R.addEventListener("focusin",S);
function tick(){if(au<0)return;if(V)go((I+1)%n);au=setTimeout(tick,IDLE)}
new IntersectionObserver(function(e){V=e[0].isIntersecting;V&&k()}).observe(R);
function A(){au=setTimeout(tick,2200)}rm||(document.readyState=="complete"?A():addEventListener("load",A));
})();
</script>

With reduced motion: Photos and captions swap straight to the chosen slide with no tile sweep and no glide.

Running cost: The canvas paints forty tiles only during a change of under a second, then a plain image takes over.

  • Change `COLS` and `ROWS` for coarser or finer tiles, and `DUR` for a slower or quicker sweep.
  • Lower `FRICTION` toward 0.9 so a flick stops sooner, or raise it to 0.95 for a longer coast.
  • Recolour the paper, ink and rust accent with `--w2til-bg`, `--w2til-ink` and `--w2til-acc` in the HTML version, and set caption width with `--w2til-item`.

Cover Flow Record Slider With Centre Focus

Square record sleeves for a small label sit in a row on a navy stage. The one in the middle faces you at full size, and the others turn away on rotateY, shrink and sink back the further they are from centre. Drag to spin through them with momentum; the nearest sleeve always lands dead centre. Fits album, book or poster ranges.

<section class="w1cov" role="region" aria-roledescription="carousel" aria-label="New pressings from Tidewater Records">
  <div class="w1cov-head">
    <p class="w1cov-kick">Tidewater Records</p>
    <h2 class="w1cov-title">New pressings on the shelf</h2>
  </div>
  <div class="w1cov-view">
    <div class="w1cov-track">
      <div class="w1cov-slide" role="group" aria-roledescription="slide" aria-label="1 of 7" data-name="Low Tide Hours"><a class="w1cov-card w1cov-c1" href="#" draggable="false"><span class="w1cov-art w1cov-stripe" aria-hidden="true"></span><span class="w1cov-txt"><span class="w1cov-t">Low Tide Hours</span><span class="w1cov-a">Marla Quist</span></span></a></div>
      <div class="w1cov-slide" role="group" aria-roledescription="slide" aria-label="2 of 7" data-name="Harbour Lights"><a class="w1cov-card w1cov-c2" href="#" draggable="false"><span class="w1cov-art w1cov-circle" aria-hidden="true"></span><span class="w1cov-txt"><span class="w1cov-t">Harbour Lights</span><span class="w1cov-a">The Fenwick Trio</span></span></a></div>
      <div class="w1cov-slide" role="group" aria-roledescription="slide" aria-label="3 of 7" data-name="Salt and Cedar"><a class="w1cov-card w1cov-c3" href="#" draggable="false"><span class="w1cov-art w1cov-arc" aria-hidden="true"></span><span class="w1cov-txt"><span class="w1cov-t">Salt and Cedar</span><span class="w1cov-a">Juno Ashby</span></span></a></div>
      <div class="w1cov-slide" role="group" aria-roledescription="slide" aria-label="4 of 7" data-name="North Pier"><a class="w1cov-card w1cov-c4" href="#" draggable="false"><span class="w1cov-art w1cov-grid" aria-hidden="true"></span><span class="w1cov-txt"><span class="w1cov-t">North Pier</span><span class="w1cov-a">Ola Brennan</span></span></a></div>
      <div class="w1cov-slide" role="group" aria-roledescription="slide" aria-label="5 of 7" data-name="Slow Current"><a class="w1cov-card w1cov-c5" href="#" draggable="false"><span class="w1cov-art w1cov-circle" aria-hidden="true"></span><span class="w1cov-txt"><span class="w1cov-t">Slow Current</span><span class="w1cov-a">Ivo and the Shoals</span></span></a></div>
      <div class="w1cov-slide" role="group" aria-roledescription="slide" aria-label="6 of 7" data-name="Fog Signals"><a class="w1cov-card w1cov-c6" href="#" draggable="false"><span class="w1cov-art w1cov-stripe" aria-hidden="true"></span><span class="w1cov-txt"><span class="w1cov-t">Fog Signals</span><span class="w1cov-a">Marla Quist</span></span></a></div>
      <div class="w1cov-slide" role="group" aria-roledescription="slide" aria-label="7 of 7" data-name="Winter Ferry"><a class="w1cov-card w1cov-c7" href="#" draggable="false"><span class="w1cov-art w1cov-arc" aria-hidden="true"></span><span class="w1cov-txt"><span class="w1cov-t">Winter Ferry</span><span class="w1cov-a">Hollis Day</span></span></a></div>
    </div>
  </div>
  <div class="w1cov-foot">
    <button class="w1cov-btn w1cov-prev" type="button" aria-label="Previous slide"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M15 5l-7 7 7 7" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
    <p class="w1cov-count">Salt and Cedar</p>
    <button class="w1cov-btn w1cov-next" type="button" aria-label="Next slide"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M9 5l7 7-7 7" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
  </div>
  <p class="w1cov-live" aria-live="polite"></p>
</section>
<style>
  /* Change these: background, text, sleeve size, depth of the 3D view. */
  .w1cov { --w1cov-bg: #0f1a2b; --w1cov-text: #eef1f5; --w1cov-size: clamp(190px, 24vw, 270px); --w1cov-depth: 900px; }
  .w1cov, .w1cov * { box-sizing: border-box; }
  .w1cov { position: relative; overflow: hidden; background: radial-gradient(ellipse at 50% 60%, #1b2b45 0%, var(--w1cov-bg) 65%); color: var(--w1cov-text); padding: 60px 0 52px; font-family: ui-sans-serif, system-ui, sans-serif; text-align: center; }
  .w1cov-kick { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .24em; text-transform: uppercase; color: #c9a46b; }
  .w1cov-title { margin: 12px 0 0; font-size: clamp(28px, 4vw, 42px); font-weight: 600; letter-spacing: -.02em; }
  .w1cov-view { margin-top: 40px; overflow: hidden; perspective: var(--w1cov-depth); }
  .w1cov-track { display: flex; width: max-content; padding: 20px 0 40px; touch-action: pan-y; cursor: grab; user-select: none; -webkit-user-select: none; transform-style: preserve-3d; will-change: transform; }
  .w1cov-track:active { cursor: grabbing; }
  .w1cov-slide { position: relative; width: calc(var(--w1cov-size) * .62); flex: none; transform-style: preserve-3d; }
  .w1cov-card { position: relative; display: block; width: var(--w1cov-size); margin-left: calc(var(--w1cov-size) * -.19); aspect-ratio: 1; border-radius: 3px; overflow: hidden; background: var(--bg); color: var(--fg); text-decoration: none; text-align: left; box-shadow: 0 30px 40px -24px rgba(0, 0, 0, .8); will-change: transform; -webkit-box-reflect: below 2px linear-gradient(transparent 70%, rgba(255, 255, 255, .12)); }
  .w1cov-card:focus-visible, .w1cov-btn:focus-visible { outline: 2px solid #c9a46b; outline-offset: 4px; }
  .w1cov-c1 { --bg: #c9a46b; --fg: #23324a; }
  .w1cov-c2 { --bg: #d9d2c3; --fg: #8a3b2e; }
  .w1cov-c3 { --bg: #e7dcc7; --fg: #2f5d62; }
  .w1cov-c4 { --bg: #1d2433; --fg: #d4a24c; }
  .w1cov-c5 { --bg: #7a8f9e; --fg: #f0e8da; }
  .w1cov-c6 { --bg: #b7553a; --fg: #f2e6d0; }
  .w1cov-c7 { --bg: #e8e2d6; --fg: #22303f; }
  .w1cov-art { position: absolute; inset: 0; }
  .w1cov-circle::before { content: ""; position: absolute; width: 58%; aspect-ratio: 1; left: 21%; top: 14%; border-radius: 50%; background: var(--fg); opacity: .9; }
  .w1cov-stripe { inset: 0 0 38% 0; background: repeating-linear-gradient(90deg, transparent 0 14px, var(--fg) 14px 18px); opacity: .55; }
  .w1cov-arc::before { content: ""; position: absolute; width: 130%; aspect-ratio: 1; left: -15%; top: 46%; border-radius: 50%; border: 14px solid var(--fg); opacity: .8; }
  .w1cov-grid::before { content: ""; position: absolute; left: 16px; right: 16px; top: 16px; height: 46%; border-top: 3px solid var(--fg); border-bottom: 3px solid var(--fg); background: repeating-linear-gradient(0deg, transparent 0 18px, var(--fg) 18px 20px); opacity: .85; }
  .w1cov-txt { position: absolute; left: 16px; right: 16px; bottom: 14px; }
  .w1cov-t { display: block; font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
  .w1cov-a { display: block; margin-top: 2px; font-size: 12px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; }
  .w1cov-foot { display: flex; align-items: center; justify-content: center; gap: 20px; }
  .w1cov-count { margin: 0; min-width: 11rem; font-size: 16px; font-weight: 600; }
  .w1cov-btn { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 999px; border: 1px solid rgba(238, 241, 245, .3); background: transparent; color: inherit; cursor: pointer; transition: opacity .2s, background-color .2s; }
  .w1cov-btn:hover:not(:disabled) { background: rgba(238, 241, 245, .1); }
  .w1cov-btn:disabled { opacity: .35; cursor: default; }
  .w1cov-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  @media (prefers-reduced-motion: reduce) { .w1cov-btn { transition: none; } }
</style>
<script>
(function(){
/* Change these: glide friction, snap spring, damping, how far side sleeves turn (deg), idle advance (ms). */
var FRICTION=.94,SPRING=.09,DAMP=.72,TURN=48,IDLE=4000;
function init(R){
var q=s=>R.querySelector(".w1cov-"+s),V=q("view"),T=q("track"),C=q("count"),L=q("live"),P=q("prev"),N=q("next"),
S=[...R.querySelectorAll(".w1cov-slide")],n=S.length,rm=matchMedia("(prefers-reduced-motion: reduce)").matches,
x=0,v=0,lo=0,hi=0,pts=[],i=0,mode=0,tgt=0,raf=0,fr=0,d=0,moved=0,h=[],vis=1,idle=0,
ac=new AbortController(),on=(el,t,f,c)=>el.addEventListener(t,f,{signal:ac.signal,capture:!!c}),
M=Math,A=M.abs,cl=(a,b,c)=>M.max(b,M.min(c,a)),rq=requestAnimationFrame,ca=cancelAnimationFrame,
near=p=>{var b=0;pts.forEach((t,k)=>{if(A(t-p)<A(pts[b]-p))b=k});return b};
/* every slide has a resting x that puts its centre in the middle of the view */
function ms(){pts=S.map(s=>V.clientWidth/2-s.offsetLeft-s.offsetWidth/2);hi=pts[0];lo=pts[n-1];x=pts[i];draw()}
function draw(){T.style.transform="translate3d("+x+"px,0,0)";i=near(x);
S.forEach((s,k)=>{var w=s.offsetWidth,e=cl((pts[k]-x)/w,-3,3),a=A(e);
/* distance from centre turns, shrinks and pushes back each sleeve */
s.firstElementChild.style.transform=`translate3d(${-e*w*.38}px,0,${-a*120}px) rotateY(${cl(e*TURN,-TURN,TURN)}deg) scale(${1-M.min(a,2)*.08})`;
s.style.zIndex=99-M.round(a*9)});
C.textContent=S[i].dataset.name;P.disabled=!i;N.disabled=i==n-1}
function loop(){
if(mode==1){x+=v;v*=x>hi||x<lo?.6:FRICTION;if(A(v)<3){mode=2;tgt=pts[near(x+v*9)]}}
else{v=(v+(tgt-x)*SPRING)*DAMP;x+=v;if(A(tgt-x)<.4&&A(v)<.4){x=tgt;mode=0}}
draw();raf=mode&&vis?rq(loop):0}
function run(){if(!raf&&mode&&vis)raf=rq(loop)}
function go(k,say){k=cl(k,0,n-1);tgt=pts[k];
if(rm){mode=0;x=tgt;draw()}else{mode=2;run()}
if(say)L.textContent="Slide "+(k+1)+" of "+n}
function stop(){clearInterval(idle)}
on(T,"pointerdown",e=>{if(e.button)return;stop();ca(raf);raf=mode=moved=0;d={p:e.clientX,s:x,id:e.pointerId};h=[[e.timeStamp,x]]});
on(T,"pointermove",e=>{if(!d)return;var m=d.s+e.clientX-d.p,t=e.timeStamp;
if(!moved&&A(m-d.s)>6){moved=1;T.setPointerCapture(d.id)}
if(!moved)return;
x=m>hi?hi+(m-hi)*.35:m<lo?lo+(m-lo)*.35:m;
h.push([t,x]);while(h.length>2&&t-h[0][0]>100)h.shift();
if(!fr)fr=rq(()=>{fr=0;draw()})});
function up(e){if(!d)return;d=0;if(!moved)return;
var a=h[0],b=h[h.length-1],t=b[0]-a[0];
/* release speed from the last 100 ms of moves */
v=t>0&&e.timeStamp-b[0]<80?(b[1]-a[1])/t*16.7:0;
if(rm)go(near(x));else{mode=1;run()}}
on(T,"pointerup",up);on(T,"pointercancel",up);
on(T,"click",e=>{if(moved){e.preventDefault();e.stopPropagation();moved=0}},1);
on(P,"click",()=>{stop();go(i-1,1)});on(N,"click",()=>{stop();go(i+1,1)});
on(R,"keydown",e=>{var k={ArrowLeft:-1,ArrowRight:1}[e.key];if(k){e.preventDefault();stop();go(i+k,1)}});
on(R,"focusin",e=>{stop();V.scrollLeft=0;var s=e.target.closest(".w1cov-slide");if(s)go(S.indexOf(s))});
on(R,"pointerenter",stop);
var io=new IntersectionObserver(en=>{vis=en[0].isIntersecting;if(vis)run();else{ca(raf);raf=0}});
on(window,"resize",ms);io.observe(R);i=2;ms();
/* idle demo: one sleeve every IDLE ms until the pointer arrives or anything is pressed */
if(!rm)idle=setInterval(()=>vis&&!document.hidden&&go(i<n-1?i+1:0),IDLE);
return()=>{ac.abort();io.disconnect();stop();ca(raf);ca(fr)}}
var R=document.querySelector(".w1cov");if(R)init(R);
})();
</script>

With reduced motion: Sleeves keep their angled cover flow layout, but buttons and keys switch the centre sleeve at once and a drag lands without any glide.

Running cost: Each frame of a drag writes one transform per sleeve, seven in this demo, all on composited layers, and nothing runs at rest.

  • Change `TURN` to set how far the side sleeves angle away, from 30 for subtle to 60 for steep.
  • Size the sleeves with `--w1cov-size` and soften or sharpen the 3D with `--w1cov-depth`.
  • Each sleeve's colours live in the `.w1cov-c1` to `.w1cov-c7` rules as `--bg` and `--fg`.

Flick Away Stacked Card Deck Slider

A plant shop's weekly picks stacked like a hand of cards. Grab the top card and it tilts with your drag; let go fast or far enough and it keeps flying at the speed you threw it while the card underneath rises into place, then it tucks in at the back of the deck. A short drag springs back. The deck loops, so it suits a small rotating selection.

<section class="w2dek" role="region" aria-roledescription="carousel" aria-label="Fernhall plants this week">
  <div class="w2dek-wrap">
    <div class="w2dek-copy">
      <p class="w2dek-kicker">Fernhall Plant Shop</p>
      <h2 class="w2dek-title">On the bench this week</h2>
      <p class="w2dek-text">Flick the top card away to see the next plant, or use the arrows. Every plant is potted in our back room on Harrow Lane.</p>
      <div class="w2dek-btns">
        <button class="w2dek-btn" type="button" data-d="-1" aria-label="Previous plant"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M15 5l-7 7 7 7" fill="none" stroke="currentColor" stroke-width="2"/></svg></button>
        <button class="w2dek-btn" type="button" data-d="1" aria-label="Next plant"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M9 5l7 7-7 7" fill="none" stroke="currentColor" stroke-width="2"/></svg></button>
        <span class="w2dek-count" aria-hidden="true">1 / 5</span>
      </div>
    </div>
    <div class="w2dek-deck">
      <article class="w2dek-card" role="group" aria-roledescription="slide" aria-label="1 of 5"><img src="https://images.pexels.com/photos/12014192/pexels-photo-12014192.jpeg?auto=compress&cs=tinysrgb&w=800" alt="Monstera plant on a black stand beside a sunny window" draggable="false"><div class="w2dek-info"><div><h3>Monstera</h3><p>Deliciosa, 70 cm</p></div><a href="#">View plant <span>38.00</span></a></div></article>
      <article class="w2dek-card" role="group" aria-roledescription="slide" aria-label="2 of 5"><img src="https://images.pexels.com/photos/29218657/pexels-photo-29218657.jpeg?auto=compress&cs=tinysrgb&w=800" alt="Snake plant in a white ribbed pot on a red table" draggable="false"><div class="w2dek-info"><div><h3>Snake plant</h3><p>White pot, 45 cm</p></div><a href="#">View plant <span>24.00</span></a></div></article>
      <article class="w2dek-card" role="group" aria-roledescription="slide" aria-label="3 of 5"><img src="https://images.pexels.com/photos/12683407/pexels-photo-12683407.jpeg?auto=compress&cs=tinysrgb&w=800" alt="Small round cactus in a terracotta pot by an open window" draggable="false"><div class="w2dek-info"><div><h3>Barrel cactus</h3><p>12 cm terracotta</p></div><a href="#">View plant <span>12.50</span></a></div></article>
      <article class="w2dek-card" role="group" aria-roledescription="slide" aria-label="4 of 5"><img src="https://images.pexels.com/photos/10903261/pexels-photo-10903261.jpeg?auto=compress&cs=tinysrgb&w=800" alt="Lush potted ferns in terracotta in soft sunlight" draggable="false"><div class="w2dek-info"><div><h3>Boston fern</h3><p>Likes it damp</p></div><a href="#">View plant <span>19.00</span></a></div></article>
      <article class="w2dek-card" role="group" aria-roledescription="slide" aria-label="5 of 5"><img src="https://images.pexels.com/photos/35920773/pexels-photo-35920773.jpeg?auto=compress&cs=tinysrgb&w=800" alt="A group of leafy plants in terracotta pots on a wooden table" draggable="false"><div class="w2dek-info"><div><h3>Terracotta trio</h3><p>Three small pots</p></div><a href="#">View plant <span>31.00</span></a></div></article>
    </div>
    <p class="w2dek-live" aria-live="polite"></p>
  </div>
</section>
<style>
  /* Change these: sand background, ink, olive accent, card width. */
  .w2dek { --w2dek-bg: #ede3d1; --w2dek-ink: #2e2a22; --w2dek-acc: #5d6a2c; --w2dek-w: 300px; }
  .w2dek { background: var(--w2dek-bg); color: var(--w2dek-ink); padding: 56px 16px 64px; font-family: ui-sans-serif, system-ui, sans-serif; overflow: hidden; }
  .w2dek-wrap { max-width: 980px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 40px; align-items: center; }
  @media (min-width: 768px) { .w2dek-wrap { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
  .w2dek-kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .24em; text-transform: uppercase; color: var(--w2dek-acc); }
  .w2dek-title { margin: 12px 0 0; font: 600 clamp(30px, 4vw, 44px)/1.1 Georgia, "Times New Roman", serif; }
  .w2dek-text { margin: 16px 0 0; max-width: 26rem; font-size: 16px; line-height: 1.65; color: #5a5245; }
  .w2dek-btns { display: flex; align-items: center; gap: 10px; margin-top: 28px; }
  .w2dek-btn { width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--w2dek-ink); color: var(--w2dek-bg); display: grid; place-items: center; cursor: pointer; }
  .w2dek-btn:hover { background: #4a4437; }
  .w2dek-count { margin-left: 8px; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; color: #5a5245; }
  .w2dek-deck { position: relative; width: var(--w2dek-w); max-width: 100%; height: 490px; margin: 0 auto; touch-action: pan-y; user-select: none; }
  .w2dek-card { position: absolute; inset: 0 0 auto; height: 440px; border-radius: 18px; overflow: hidden; background: #fbf7ef; box-shadow: 0 18px 36px -22px rgba(50, 40, 20, .5); transition: transform .45s cubic-bezier(.2, .8, .2, 1), opacity .45s; cursor: grab; will-change: transform; transform-origin: 50% 100%; }
  .w2dek-card img { display: block; width: 100%; height: 330px; object-fit: cover; pointer-events: none; }
  .w2dek-info { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 14px 0 18px; height: 110px; }
  .w2dek-info h3 { margin: 0; font: 600 20px/1.2 Georgia, "Times New Roman", serif; }
  .w2dek-info p { margin: 2px 0 0; font-size: 13px; color: #5a5245; }
  .w2dek-info a { flex: none; display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px; border-radius: 999px; background: #e7dcc6; color: var(--w2dek-ink); font-size: 13px; font-weight: 600; text-decoration: none; }
  .w2dek-info a span { color: var(--w2dek-acc); }
  .w2dek-btn:focus-visible, .w2dek-info a:focus-visible { outline: 2px solid var(--w2dek-acc); outline-offset: 3px; }
  .w2dek-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .w2dek-info > * { transition: opacity .3s; }
  .w2dek-card[inert] .w2dek-info > * { opacity: 0; }
  @media (prefers-reduced-motion: reduce) { .w2dek-card { transition: none; } }
</style>
<script>
(function(){
/* Change these: throw distance as a share of card width, flick speed (px per frame), idle advance in ms. */
var THROW=.35,FLICK=9,IDLE=3000;
var R=document.querySelector(".w2dek"),Q=function(s){return R.querySelectorAll(s)},M=Math,F=requestAnimationFrame;
var dk=Q(".w2dek-deck")[0],cs=[].slice.call(Q(".w2dek-card")),bt=Q(".w2dek-btn"),lv=Q(".w2dek-live")[0],ct=Q(".w2dek-count")[0];
var n=cs.length,rm=matchMedia("(prefers-reduced-motion: reduce)").matches,od=cs.slice(),x=0,v=0,raf=0,dn=0,fly=0,sx,x0,H,mv,V=1,au=0,an=0;
function pos(c,d,t){c.style.transition=t?"":"none";c.style.zIndex=n-d;c.style.opacity=d>3?0:1;c.inert=d>0;
c.style.transform="translate3d(0,"+d*16+"px,0) scale("+(1-d*.05)+")"}
function lay(t){t!=null&&od.forEach(function(c,d){d>1&&pos(c,d,t)});var c=od[0],p=M.min(M.abs(x)/dk.offsetWidth,1);
c.inert=0;c.style.zIndex=n;c.style.opacity=1;c.style.transition=t?"":"none";c.style.transform="translate3d("+x+"px,"+M.abs(x)*.06+"px,0) rotate("+x*.04+"deg)";
/* the next card rises toward the top as the top one leaves */
od[1].style.transition=t?"":"none";od[1].style.transform="translate3d(0,"+16*(1-p)+"px,0) scale("+(.95+.05*p)+")";}
function say(){var i=cs.indexOf(od[0]);ct.textContent=i+1+" / "+n;return"Plant "+(i+1)+" of "+n+": "+od[0].querySelector("h3").textContent}
function loop(){raf=0;var w=dk.offsetWidth;
if(!dn){if(fly){x+=v;v*=1.02;if(M.abs(x)>w*1.7){od.push(od.shift());x=0;v=0;fly=0;pos(od[n-1],n-1);var t=say();if(an)lv.textContent=t;an=0;return lay(1)}}
else{v=(v+(0-x)*.12)*.74;x+=v;if(M.abs(x)<.5&&M.abs(v)<.5){x=0;return lay(1)}}}
lay();raf=F(loop)}
function k(){raf=raf||F(loop)}
function next(d){if(rm){od.push(od.shift());say();return lay(0)}fly=1;v=d*FLICK*2;k()}
function prev(){od.unshift(od.pop());say();if(rm)return lay(0);x=-dk.offsetWidth*1.4;fly=0;v=0;lay(1);k()}
function S(){clearTimeout(au);au=-1}
function go(d){S();d>0?next(1):prev();if(d<0||rm)lv.textContent=say();else an=1}
dk.onpointerdown=function(e){if(fly)return;S();dn=1;mv=0;sx=e.clientX;x0=x;v=0;k()};
dk.onpointermove=function(e){if(!dn)return;var d=e.clientX-sx;if(M.abs(d)>6&&!mv){mv=1;dk.setPointerCapture(e.pointerId)}v=v*.5+(x0+d-x)*.5;x=x0+d;H=e.timeStamp;k()};
dk.onpointerup=dk.onpointercancel=function(e){if(!dn)return;dn=0;if(e.timeStamp-H>100)v=0;
if(M.abs(x)>dk.offsetWidth*THROW||M.abs(v)>FLICK){if(rm){x=0;next(1)}else{fly=1;v=(x<0?-1:1)*M.max(M.abs(v),FLICK)}}else if(rm)x=0;k()};
dk.addEventListener("click",function(e){if(mv){e.preventDefault();e.stopPropagation()}},true);
bt.forEach(function(b){b.onclick=function(){go(+b.dataset.d)}});
R.onkeydown=function(e){var d={ArrowLeft:-1,ArrowRight:1}[e.key];if(d){e.preventDefault();go(d)}};
R.onpointerenter=S;R.addEventListener("focusin",S);
function tick(){if(au<0)return;if(V&&!fly)next(1);au=setTimeout(tick,IDLE)}
new IntersectionObserver(function(e){V=e[0].isIntersecting;if(!V){cancelAnimationFrame(raf);raf=0}else if(fly||x)k()}).observe(R);
lay(0);
function A(){au=setTimeout(tick,2200)}rm||(document.readyState=="complete"?A():addEventListener("load",A));
})();
</script>

With reduced motion: Cards swap order instantly on a flick, button or arrow key, with no throw and no spring.

Running cost: Only the top two cards are written each frame while dragging or flying, and the loop ends as soon as the deck settles.

  • Change `THROW` for how far a drag must go before the card leaves, and `FLICK` for the release speed that throws it regardless of distance.
  • Set the card size with `--w2dek-w` and the `.w2dek-card` height, and the stacking gap with the `16` in `pos()`.
  • Recolour sand, ink and olive with `--w2dek-bg`, `--w2dek-ink` and `--w2dek-acc`.

Free Scroll Plant Strip That Coasts Then Springs

A deep green nursery strip of narrow plant cards. Low friction lets a flick coast a long way, and when it slows a soft spring carries it a little past the nearest card and back. The card closest to the left edge is lit while the rest dim, and its name shows beside the arrows. Good for a long, loose product row.

<section class="w1fre" role="region" aria-roledescription="carousel" aria-label="Plants at Ostler Glasshouse">
  <div class="w1fre-head">
    <p class="w1fre-kick">Ostler Glasshouse, Bristol</p>
    <h2 class="w1fre-title">This week on the potting bench</h2>
    <p class="w1fre-copy">Flick the row and let it coast. It slows on its own and springs back onto the nearest plant.</p>
  </div>
  <div class="w1fre-view">
    <div class="w1fre-track">
      <div class="w1fre-slide" role="group" aria-roledescription="slide" aria-label="1 of 7" data-name="Snake plant"><a class="w1fre-card" href="#" draggable="false"><span class="w1fre-ph"><img src="https://images.pexels.com/photos/10467813/pexels-photo-10467813.jpeg?auto=compress&cs=tinysrgb&w=600" alt="A tall snake plant in a white ceramic pot beside a small cabinet" width="480" height="640" draggable="false"></span><span class="w1fre-row"><span class="w1fre-name">Snake plant</span><span class="w1fre-price">£34</span></span><span class="w1fre-note">White ceramic pot, 60 cm</span></a></div>
      <div class="w1fre-slide" role="group" aria-roledescription="slide" aria-label="2 of 7" data-name="Boston fern"><a class="w1fre-card" href="#" draggable="false"><span class="w1fre-ph"><img src="https://images.pexels.com/photos/10903261/pexels-photo-10903261.jpeg?auto=compress&cs=tinysrgb&w=600" alt="A full Boston fern in a terracotta pot on a wooden floor" width="480" height="640" draggable="false"></span><span class="w1fre-row"><span class="w1fre-name">Boston fern</span><span class="w1fre-price">£22</span></span><span class="w1fre-note">Terracotta, bright shade</span></a></div>
      <div class="w1fre-slide" role="group" aria-roledescription="slide" aria-label="3 of 7" data-name="Monstera on a stand"><a class="w1fre-card" href="#" draggable="false"><span class="w1fre-ph"><img src="https://images.pexels.com/photos/12014192/pexels-photo-12014192.jpeg?auto=compress&cs=tinysrgb&w=600" alt="A monstera in a white pot on a black metal stand by a window" width="480" height="640" draggable="false"></span><span class="w1fre-row"><span class="w1fre-name">Monstera on a stand</span><span class="w1fre-price">£48</span></span><span class="w1fre-note">Black iron plant stand</span></a></div>
      <div class="w1fre-slide" role="group" aria-roledescription="slide" aria-label="4 of 7" data-name="Parlour palm"><a class="w1fre-card" href="#" draggable="false"><span class="w1fre-ph"><img src="https://images.pexels.com/photos/30343587/pexels-photo-30343587.jpeg?auto=compress&cs=tinysrgb&w=600" alt="Soft green palm fronds above a terracotta pot" width="480" height="640" draggable="false"></span><span class="w1fre-row"><span class="w1fre-name">Parlour palm</span><span class="w1fre-price">£26</span></span><span class="w1fre-note">Terracotta, low light</span></a></div>
      <div class="w1fre-slide" role="group" aria-roledescription="slide" aria-label="5 of 7" data-name="Holly fern"><a class="w1fre-card" href="#" draggable="false"><span class="w1fre-ph"><img src="https://images.pexels.com/photos/35920773/pexels-photo-35920773.jpeg?auto=compress&cs=tinysrgb&w=600" alt="A holly fern in a small terracotta pot on a wooden table" width="480" height="640" draggable="false"></span><span class="w1fre-row"><span class="w1fre-name">Holly fern</span><span class="w1fre-price">£14</span></span><span class="w1fre-note">Small clay pot</span></a></div>
      <div class="w1fre-slide" role="group" aria-roledescription="slide" aria-label="6 of 7" data-name="Young monstera"><a class="w1fre-card" href="#" draggable="false"><span class="w1fre-ph"><img src="https://images.pexels.com/photos/9088036/pexels-photo-9088036.jpeg?auto=compress&cs=tinysrgb&w=600" alt="A young monstera with split leaves in a dark pot against a warm wall" width="480" height="640" draggable="false"></span><span class="w1fre-row"><span class="w1fre-name">Young monstera</span><span class="w1fre-price">£19</span></span><span class="w1fre-note">Glazed navy pot</span></a></div>
      <div class="w1fre-slide" role="group" aria-roledescription="slide" aria-label="7 of 7" data-name="Windowsill pair"><a class="w1fre-card" href="#" draggable="false"><span class="w1fre-ph"><img src="https://images.pexels.com/photos/12951672/pexels-photo-12951672.jpeg?auto=compress&cs=tinysrgb&w=600" alt="A fern and a striped calathea in pots on a sunny windowsill" width="480" height="640" draggable="false"></span><span class="w1fre-row"><span class="w1fre-name">Windowsill pair</span><span class="w1fre-price">£30</span></span><span class="w1fre-note">Fern and calathea</span></a></div>
    </div>
  </div>
  <div class="w1fre-foot">
    <p class="w1fre-now"><span class="w1fre-dim">Nearest</span> <span class="w1fre-count">Snake plant</span></p>
    <div class="w1fre-nav">
      <button class="w1fre-btn w1fre-prev" type="button" aria-label="Previous slide"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M19 12H5m6-6l-6 6 6 6" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
      <button class="w1fre-btn w1fre-next" type="button" aria-label="Next slide"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M5 12h14m-6-6l6 6-6 6" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
    </div>
  </div>
  <p class="w1fre-live" aria-live="polite"></p>
</section>
<style>
  /* Change these: background, text, leaf accent, card width. */
  .w1fre { --w1fre-bg: #1d2a22; --w1fre-text: #eef0e6; --w1fre-leaf: #b9cf8f; --w1fre-card: clamp(190px, 21vw, 240px); }
  .w1fre, .w1fre * { box-sizing: border-box; }
  .w1fre { position: relative; overflow: hidden; background: var(--w1fre-bg); color: var(--w1fre-text); padding: 64px 0 52px; font-family: ui-sans-serif, system-ui, sans-serif; }
  .w1fre-head, .w1fre-foot { max-width: 72rem; margin: 0 auto; padding: 0 24px; }
  .w1fre-kick { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .22em; text-transform: uppercase; color: var(--w1fre-leaf); }
  .w1fre-title { margin: 12px 0 0; font-size: clamp(28px, 4vw, 42px); font-weight: 600; letter-spacing: -.02em; line-height: 1.1; }
  .w1fre-copy { margin: 12px 0 0; max-width: 34rem; font-size: 15px; line-height: 1.6; color: #c3c9b9; }
  .w1fre-view { margin-top: 36px; overflow: hidden; }
  .w1fre-track { position: relative; display: flex; gap: 16px; width: max-content; padding: 4px calc(100vw - var(--w1fre-card) - max(24px, calc((100vw - 72rem) / 2 + 24px))) 8px max(24px, calc((100vw - 72rem) / 2 + 24px)); touch-action: pan-y; cursor: grab; user-select: none; -webkit-user-select: none; will-change: transform; }
  .w1fre-track:active { cursor: grabbing; }
  .w1fre-slide { width: var(--w1fre-card); flex: none; opacity: .62; transition: opacity .45s ease; }
  .w1fre-slide.w1fre-on, .w1fre-slide:focus-within { opacity: 1; }
  .w1fre-card { display: block; color: inherit; text-decoration: none; border-radius: 14px; }
  .w1fre-card:focus-visible, .w1fre-btn:focus-visible { outline: 2px solid var(--w1fre-leaf); outline-offset: 4px; }
  .w1fre-ph { display: block; aspect-ratio: 3 / 4; overflow: hidden; border-radius: 14px; background: #2b3a30; box-shadow: 0 18px 30px -20px rgba(0, 0, 0, .7); }
  .w1fre-ph img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
  .w1fre-row { display: flex; justify-content: space-between; gap: 8px; margin-top: 12px; font-size: 16px; font-weight: 600; }
  .w1fre-price { font-variant-numeric: tabular-nums; color: var(--w1fre-leaf); }
  .w1fre-note { display: block; margin-top: 3px; font-size: 13px; color: #c3c9b9; }
  .w1fre-foot { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 28px; }
  .w1fre-now { margin: 0; font-size: 15px; }
  .w1fre-dim { color: #a9b2a0; margin-right: 6px; }
  .w1fre-count { font-weight: 600; }
  .w1fre-nav { display: flex; gap: 8px; }
  .w1fre-btn { display: grid; place-items: center; width: 52px; height: 44px; border-radius: 999px; border: 0; background: #2f4136; color: var(--w1fre-text); cursor: pointer; transition: background-color .2s, opacity .2s; }
  .w1fre-btn:hover:not(:disabled) { background: #3d5446; }
  .w1fre-btn:disabled { opacity: .35; cursor: default; }
  .w1fre-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  @media (prefers-reduced-motion: reduce) { .w1fre-slide, .w1fre-btn { transition: none; } }
</style>
<script>
(function(){
/* Change these: glide friction (nearer 1 coasts further), spring stiffness, spring damping (higher = more overshoot), idle advance (ms). */
var FRICTION=.965,SPRING=.07,DAMP=.82,IDLE=4000;
function init(R){
var q=s=>R.querySelector(".w1fre-"+s),V=q("view"),T=q("track"),C=q("count"),L=q("live"),P=q("prev"),N=q("next"),
S=[...R.querySelectorAll(".w1fre-slide")],n=S.length,rm=matchMedia("(prefers-reduced-motion: reduce)").matches,
x=0,v=0,min=0,pts=[0],i=0,mode=0,tgt=0,raf=0,fr=0,d=0,moved=0,h=[],vis=1,idle=0,
ac=new AbortController(),on=(el,t,f,c)=>el.addEventListener(t,f,{signal:ac.signal,capture:!!c}),
M=Math,A=M.abs,cl=(a,lo,hi)=>M.max(lo,M.min(hi,a)),rq=requestAnimationFrame,ca=cancelAnimationFrame,
last=()=>pts.length-1,num=k=>k==last()?n:k+1,
near=p=>{var b=0;pts.forEach((t,k)=>{if(A(t-p)<A(pts[b]-p))b=k});return b};
function measure(){min=M.min(0,V.clientWidth-T.offsetWidth);pts=[0];
S.forEach(s=>{var p=M.max(min,S[0].offsetLeft-s.offsetLeft);if(pts[last()]-p>1)pts.push(p)});
x=cl(x,min,0);draw()}
function draw(){T.style.transform="translate3d("+x+"px,0,0)";i=near(x);
/* the card nearest the left edge is lit, the rest dim with opacity */
var c=num(i)-1;S.forEach((s,k)=>s.classList.toggle("w1fre-on",k==c));
C.textContent=S[c].dataset.name;P.disabled=x>-1;N.disabled=x<min+1}
function loop(){
/* mode 1 = coasting with friction, mode 2 = spring onto the chosen slide */
if(mode==1){x+=v;v*=x>0||x<min?.6:FRICTION;if(A(v)<3){mode=2;tgt=pts[near(x+v*9)]}}
else{v=(v+(tgt-x)*SPRING)*DAMP;x+=v;if(A(tgt-x)<.4&&A(v)<.4){x=tgt;mode=0}}
draw();raf=mode&&vis?rq(loop):0}
function run(){if(!raf&&mode&&vis)raf=rq(loop)}
function go(k,say){k=cl(k,0,last());tgt=pts[k];
if(rm){mode=0;x=tgt;draw()}else{mode=2;run()}
if(say)L.textContent="Slide "+num(k)+" of "+n}
function stop(){clearInterval(idle)}
on(T,"pointerdown",e=>{if(e.button)return;stop();ca(raf);raf=mode=moved=0;d={p:e.clientX,s:x,id:e.pointerId};h=[[e.timeStamp,x]]});
on(T,"pointermove",e=>{if(!d)return;var m=d.s+e.clientX-d.p,t=e.timeStamp;
if(!moved&&A(m-d.s)>6){moved=1;T.setPointerCapture(d.id)}
if(!moved)return;
/* rubber band past either end */
x=m>0?m*.35:m<min?min+(m-min)*.35:m;
h.push([t,x]);while(h.length>2&&t-h[0][0]>100)h.shift();
if(!fr)fr=rq(()=>{fr=0;draw()})});
function up(e){if(!d)return;d=0;if(!moved)return;
var a=h[0],b=h[h.length-1],t=b[0]-a[0];
/* release speed from the last 100 ms of moves */
v=t>0&&e.timeStamp-b[0]<80?(b[1]-a[1])/t*16.7:0;
if(rm)go(near(x));else{mode=1;run()}}
on(T,"pointerup",up);on(T,"pointercancel",up);
/* a drag is not a click on the card link */
on(T,"click",e=>{if(moved){e.preventDefault();e.stopPropagation();moved=0}},1);
on(P,"click",()=>{stop();go(i-1,1)});on(N,"click",()=>{stop();go(i+1,1)});
on(R,"keydown",e=>{var k={ArrowLeft:-1,ArrowRight:1}[e.key];if(k){e.preventDefault();stop();go(i+k,1)}});
on(R,"focusin",e=>{stop();V.scrollLeft=0;var s=e.target.closest(".w1fre-slide");if(s)go(S.indexOf(s))});
on(R,"pointerenter",stop);
var io=new IntersectionObserver(en=>{vis=en[0].isIntersecting;if(vis)run();else{ca(raf);raf=0}});
on(window,"resize",measure);io.observe(R);measure();
/* idle demo: one slide every IDLE ms until the pointer arrives or anything is pressed */
if(!rm)idle=setInterval(()=>vis&&!document.hidden&&go(i<last()?i+1:0),IDLE);
return()=>{ac.abort();io.disconnect();stop();ca(raf);ca(fr)}}
var R=document.querySelector(".w1fre");if(R)init(R);
})();
</script>

With reduced motion: The strip follows a drag one to one and then sits on the nearest plant at once; buttons and keys jump with no spring.

Running cost: A single translate3d plus an opacity class swap per frame, and the loop ends as soon as the spring comes to rest.

  • Set `DAMP` near 0.85 for a bouncier landing, or near 0.7 to settle with no overshoot at all.
  • Lower `FRICTION` to 0.94 if a flick travels further than you want.
  • Change `--w1fre-card` for wider cards and `--w1fre-leaf` for the accent on prices and focus rings.

Full Bleed Hero Slider With Parallax Photos

A full-width hero for an architecture practice, one house per slide with its street and a project link over a soft shade. As you drag, each photo travels more slowly than its frame, so the image seems to sit behind a window passing over it. Release with speed and it carries on to the next house. Built for a homepage opener.

<section class="w1her" role="region" aria-roledescription="carousel" aria-label="Recent houses by Arden Vale Architects">
  <div class="w1her-view">
    <div class="w1her-track">
      <div class="w1her-slide" role="group" aria-roledescription="slide" aria-label="1 of 5"><span class="w1her-img"><img src="https://images.pexels.com/photos/27953061/pexels-photo-27953061.jpeg?auto=compress&cs=tinysrgb&w=1600" alt="Two white houses with steep gables against a deep blue sky" width="1600" height="1000" draggable="false"></span><span class="w1her-shade" aria-hidden="true"></span><div class="w1her-cap"><p class="w1her-place">Cove Lane, Whitstable</p><h3 class="w1her-name">Two white gables</h3><a class="w1her-link" href="#" draggable="false">View project</a></div></div>
      <div class="w1her-slide" role="group" aria-roledescription="slide" aria-label="2 of 5"><span class="w1her-img"><img src="https://images.pexels.com/photos/323780/pexels-photo-323780.jpeg?auto=compress&cs=tinysrgb&w=1600" alt="A modern white house with curved glass balconies and dark window frames" width="1600" height="1000" draggable="false"></span><span class="w1her-shade" aria-hidden="true"></span><div class="w1her-cap"><p class="w1her-place">Harbour Road, Poole</p><h3 class="w1her-name">Glass balcony house</h3><a class="w1her-link" href="#" draggable="false">View project</a></div></div>
      <div class="w1her-slide" role="group" aria-roledescription="slide" aria-label="3 of 5"><span class="w1her-img"><img src="https://images.pexels.com/photos/30580640/pexels-photo-30580640.jpeg?auto=compress&cs=tinysrgb&w=1600" alt="Two matching modern white houses with dark roofs on a new street under clouds" width="1600" height="1000" draggable="false"></span><span class="w1her-shade" aria-hidden="true"></span><div class="w1her-cap"><p class="w1her-place">Elm Street, Leiden</p><h3 class="w1her-name">Twin family homes</h3><a class="w1her-link" href="#" draggable="false">View project</a></div></div>
      <div class="w1her-slide" role="group" aria-roledescription="slide" aria-label="4 of 5"><span class="w1her-img"><img src="https://images.pexels.com/photos/7031581/pexels-photo-7031581.jpeg?auto=compress&cs=tinysrgb&w=1600" alt="A straight stone path through a green lawn beside a modern grey and timber house" width="1600" height="1000" draggable="false"></span><span class="w1her-shade" aria-hidden="true"></span><div class="w1her-cap"><p class="w1her-place">Larch Close, Ghent</p><h3 class="w1her-name">Garden path, Larch House</h3><a class="w1her-link" href="#" draggable="false">View project</a></div></div>
      <div class="w1her-slide" role="group" aria-roledescription="slide" aria-label="5 of 5"><span class="w1her-img"><img src="https://images.pexels.com/photos/19516616/pexels-photo-19516616.jpeg?auto=compress&cs=tinysrgb&w=1600" alt="A brick townhouse terrace with a stepped gable behind a clipped hedge" width="1600" height="1000" draggable="false"></span><span class="w1her-shade" aria-hidden="true"></span><div class="w1her-cap"><p class="w1her-place">Mill Row, Utrecht</p><h3 class="w1her-name">Brick terrace</h3><a class="w1her-link" href="#" draggable="false">View project</a></div></div>
    </div>
  </div>
  <div class="w1her-top">
    <h2 class="w1her-brand">Arden Vale Architects</h2>
    <p class="w1her-sub">Selected houses</p>
  </div>
  <div class="w1her-ctl">
    <p class="w1her-count" aria-hidden="true">01 / 05</p>
    <button class="w1her-btn w1her-prev" type="button" aria-label="Previous slide"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M15 5l-7 7 7 7" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
    <button class="w1her-btn w1her-next" type="button" aria-label="Next slide"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M9 5l7 7-7 7" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
  </div>
  <p class="w1her-live" aria-live="polite"></p>
</section>
<style>
  /* Change these: frame colour, text colour, slider height, darkness of the shade behind captions. */
  .w1her { --w1her-bg: #1c1d1f; --w1her-text: #f4f2ee; --w1her-h: clamp(460px, 62vw, 640px); --w1her-shade: .8; }
  .w1her, .w1her * { box-sizing: border-box; }
  .w1her { position: relative; overflow: hidden; height: var(--w1her-h); background: var(--w1her-bg); color: var(--w1her-text); font-family: ui-sans-serif, system-ui, sans-serif; }
  .w1her-view { position: absolute; inset: 0; overflow: hidden; }
  .w1her-track { display: flex; height: 100%; touch-action: pan-y; cursor: grab; user-select: none; -webkit-user-select: none; will-change: transform; }
  .w1her-track:active { cursor: grabbing; }
  .w1her-slide { position: relative; flex: 0 0 100%; height: 100%; overflow: hidden; }
  .w1her-img { position: absolute; top: 0; bottom: 0; left: -22%; width: 144%; will-change: transform; }
  .w1her-img img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
  .w1her-shade { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(20, 21, 23, .55) 0%, rgba(20, 21, 23, 0) 24%, rgba(20, 21, 23, .25) 45%, rgba(20, 21, 23, var(--w1her-shade)) 100%); }
  .w1her-cap { text-shadow: 0 1px 12px rgba(0, 0, 0, .45); position: absolute; left: max(24px, 6vw); bottom: 48px; max-width: 32rem; }
  .w1her-place { margin: 0; font-size: 13px; letter-spacing: .14em; text-transform: uppercase; color: #e2ded6; }
  .w1her-name { margin: 10px 0 0; font-size: clamp(30px, 5vw, 56px); font-weight: 500; line-height: 1.02; letter-spacing: -.025em; }
  .w1her-link { display: inline-flex; align-items: center; min-height: 44px; margin-top: 14px; padding: 0 20px; border-radius: 999px; background: var(--w1her-text); color: #1c1d1f; font-size: 14px; font-weight: 600; text-decoration: none; text-shadow: none; }
  .w1her-link:focus-visible, .w1her-btn:focus-visible { outline: 2px solid var(--w1her-text); outline-offset: 4px; }
  .w1her-top { position: absolute; top: 28px; left: max(24px, 6vw); right: 24px; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; pointer-events: none; }
  .w1her-brand { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
  .w1her-sub { margin: 0; font-size: 13px; color: #e2ded6; }
  .w1her-ctl { text-shadow: 0 1px 8px rgba(0, 0, 0, .5); position: absolute; right: max(24px, 6vw); bottom: 52px; display: flex; align-items: center; gap: 10px; }
  .w1her-count { margin: 0 10px 0 0; font-size: 14px; font-variant-numeric: tabular-nums; letter-spacing: .06em; }
  .w1her-btn { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 999px; border: 1px solid rgba(244, 242, 238, .5); background: rgba(28, 29, 31, .35); color: inherit; cursor: pointer; transition: opacity .2s, background-color .2s; }
  .w1her-btn:hover:not(:disabled) { background: rgba(28, 29, 31, .7); }
  .w1her-btn:disabled { opacity: .4; cursor: default; }
  .w1her-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  @media (max-width: 640px) { .w1her-cap { bottom: 104px; } .w1her-ctl { left: 24px; right: auto; bottom: 36px; } }
  @media (prefers-reduced-motion: reduce) { .w1her-img { left: 0; width: 100%; transform: none !important; } .w1her-btn { transition: none; } }
</style>
<script>
(function(){
/* Change these: glide friction, snap spring, damping, parallax depth (0 = none, 0.5 = image moves at half speed), idle advance (ms). */
var FRICTION=.92,SPRING=.05,DAMP=.8,DEPTH=.4,IDLE=4000;
function init(R){
var q=s=>R.querySelector(".w1her-"+s),V=q("view"),T=q("track"),C=q("count"),L=q("live"),P=q("prev"),N=q("next"),
S=[...R.querySelectorAll(".w1her-slide")],n=S.length,rm=matchMedia("(prefers-reduced-motion: reduce)").matches,
x=0,v=0,lo=0,hi=0,pts=[],i=0,mode=0,tgt=0,raf=0,fr=0,d=0,moved=0,h=[],vis=1,idle=0,
ac=new AbortController(),on=(el,t,f,c)=>el.addEventListener(t,f,{signal:ac.signal,capture:!!c}),
M=Math,A=M.abs,cl=(a,b,c)=>M.max(b,M.min(c,a)),rq=requestAnimationFrame,ca=cancelAnimationFrame,
near=p=>{var b=0;pts.forEach((t,k)=>{if(A(t-p)<A(pts[b]-p))b=k});return b};
function ms(){pts=S.map(s=>-s.offsetLeft);hi=0;lo=pts[n-1];x=pts[i];draw()}
function draw(){T.style.transform="translate3d("+x+"px,0,0)";i=near(x);
/* each photo slides the other way inside its mask, so it seems to move slower */
S.forEach((s,k)=>s.firstElementChild.style.transform=`translate3d(${(x-pts[k])*-DEPTH}px,0,0)`);
C.textContent=`0${i+1} / 0${n}`;
P.disabled=!i;N.disabled=i==n-1}
function loop(){
if(mode==1){x+=v;v*=x>hi||x<lo?.6:FRICTION;if(A(v)<3){mode=2;tgt=pts[near(x+v*9)]}}
else{v=(v+(tgt-x)*SPRING)*DAMP;x+=v;if(A(tgt-x)<.4&&A(v)<.4){x=tgt;mode=0}}
draw();raf=mode&&vis?rq(loop):0}
function run(){if(!raf&&mode&&vis)raf=rq(loop)}
function go(k,say){k=cl(k,0,n-1);tgt=pts[k];
if(rm){mode=0;x=tgt;draw()}else{mode=2;run()}
if(say)L.textContent="Slide "+(k+1)+" of "+n}
function stop(){clearInterval(idle)}
on(T,"pointerdown",e=>{if(e.button)return;stop();ca(raf);raf=mode=moved=0;d={p:e.clientX,s:x,id:e.pointerId};h=[[e.timeStamp,x]]});
on(T,"pointermove",e=>{if(!d)return;var m=d.s+e.clientX-d.p,t=e.timeStamp;
if(!moved&&A(m-d.s)>6){moved=1;T.setPointerCapture(d.id)}
if(!moved)return;
x=m>hi?hi+(m-hi)*.35:m<lo?lo+(m-lo)*.35:m;
h.push([t,x]);while(h.length>2&&t-h[0][0]>100)h.shift();
if(!fr)fr=rq(()=>{fr=0;draw()})});
function up(e){if(!d)return;d=0;if(!moved)return;
var a=h[0],b=h[h.length-1],t=b[0]-a[0];
/* release speed from the last 100 ms of moves */
v=t>0&&e.timeStamp-b[0]<80?(b[1]-a[1])/t*16.7:0;
if(rm)go(near(x));else{mode=1;run()}}
on(T,"pointerup",up);on(T,"pointercancel",up);
on(T,"click",e=>{if(moved){e.preventDefault();e.stopPropagation();moved=0}},1);
on(P,"click",()=>{stop();go(i-1,1)});on(N,"click",()=>{stop();go(i+1,1)});
on(R,"keydown",e=>{var k={ArrowLeft:-1,ArrowRight:1}[e.key];if(k){e.preventDefault();stop();go(i+k,1)}});
on(R,"focusin",e=>{stop();V.scrollLeft=0;var s=e.target.closest(".w1her-slide");if(s)go(S.indexOf(s))});
on(R,"pointerenter",stop);
var io=new IntersectionObserver(en=>{vis=en[0].isIntersecting;if(vis)run();else{ca(raf);raf=0}});
on(window,"resize",ms);io.observe(R);ms();
/* idle demo: one sleeve every IDLE ms until the pointer arrives or anything is pressed */
if(!rm)idle=setInterval(()=>vis&&!document.hidden&&go(i<n-1?i+1:0),IDLE);
return()=>{ac.abort();io.disconnect();stop();ca(raf);ca(fr)}}
var R=document.querySelector(".w1her");if(R)init(R);
})();
</script>

With reduced motion: Photos sit still inside their frames with no parallax, and each slide change is an instant jump rather than a glide.

Running cost: Two transforms per slide in view are written each frame of a drag or settle; at rest the script does nothing.

  • Set `DEPTH` between 0.2 and 0.5; higher values make the photo lag further behind its frame.
  • Change `--w1her-h` for the slider height and `--w1her-shade` for how dark the caption shade gets.
  • If you raise `DEPTH` past 0.4, widen `.w1her-img` (it is 144% wide) so the photo edge never shows.

Main Slide With Synced Draggable Thumbnail Strip

A furniture showroom's main photo above a strip of thumbnails, kept in step both ways. Drag the big photo and it coasts onto a whole slide while the strip slides to centre the matching thumbnail; drag the strip on its own and it free-scrolls with momentum and stops wherever you leave it, then a tap on any thumbnail brings that piece up. Fits product pages and room galleries.

<section class="w2thm" role="region" aria-roledescription="carousel" aria-label="Oxbow Home pieces">
  <div class="w2thm-wrap">
    <div class="w2thm-head">
      <div>
        <p class="w2thm-kicker">Oxbow Home</p>
        <h2 class="w2thm-title">New in the showroom</h2>
      </div>
      <div class="w2thm-btns">
        <button class="w2thm-btn" type="button" data-d="-1" aria-label="Previous piece" disabled><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M15 5l-7 7 7 7" fill="none" stroke="currentColor" stroke-width="2"/></svg></button>
        <button class="w2thm-btn" type="button" data-d="1" aria-label="Next piece"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M9 5l7 7-7 7" fill="none" stroke="currentColor" stroke-width="2"/></svg></button>
      </div>
    </div>
    <div class="w2thm-main" tabindex="0">
      <ol class="w2thm-track">
        <li class="w2thm-slide" role="group" aria-roledescription="slide" aria-label="1 of 6"><img src="https://images.pexels.com/photos/28529915/pexels-photo-28529915.jpeg?auto=compress&cs=tinysrgb&w=1400" alt="Wooden spindle back chair with a white seat cushion in a sunlit room" draggable="false"><div class="w2thm-cap"><h3>Spindle back chair</h3><p>Cherry with a linen pad, 340.00</p></div></li>
        <li class="w2thm-slide" role="group" aria-roledescription="slide" aria-label="2 of 6"><img src="https://images.pexels.com/photos/6758245/pexels-photo-6758245.jpeg?auto=compress&cs=tinysrgb&w=1400" alt="Grey three-seat sofa with patterned cushions in front of a leafy mural" draggable="false"><div class="w2thm-cap"><h3>Three-seat sofa</h3><p>Grey woven cover, 2,150.00</p></div></li>
        <li class="w2thm-slide" role="group" aria-roledescription="slide" aria-label="3 of 6"><img src="https://images.pexels.com/photos/6952339/pexels-photo-6952339.jpeg?auto=compress&cs=tinysrgb&w=1400" alt="White ring vase with dried grass beside a glass globe lamp on a white table" draggable="false"><div class="w2thm-cap"><h3>Ring vase and globe lamp</h3><p>Matte ceramic and opal glass, 95.00 and 160.00</p></div></li>
        <li class="w2thm-slide" role="group" aria-roledescription="slide" aria-label="4 of 6"><img src="https://images.pexels.com/photos/36799079/pexels-photo-36799079.jpeg?auto=compress&cs=tinysrgb&w=1400" alt="Table lamp with a pleated shade glowing in a cosy living room corner" draggable="false"><div class="w2thm-cap"><h3>Pleated shade lamp</h3><p>Brass base, warm bulb, 210.00</p></div></li>
        <li class="w2thm-slide" role="group" aria-roledescription="slide" aria-label="5 of 6"><img src="https://images.pexels.com/photos/14341984/pexels-photo-14341984.jpeg?auto=compress&cs=tinysrgb&w=1400" alt="Speckled white stoneware plates, bowls and mugs laid out on linen" draggable="false"><div class="w2thm-cap"><h3>Stoneware tableware</h3><p>Speckled white glaze, from 18.00</p></div></li>
        <li class="w2thm-slide" role="group" aria-roledescription="slide" aria-label="6 of 6"><img src="https://images.pexels.com/photos/38243203/pexels-photo-38243203.jpeg?auto=compress&cs=tinysrgb&w=1400" alt="Shelves of colourful glazed mugs and stacked plates" draggable="false"><div class="w2thm-cap"><h3>Glazed mugs and plates</h3><p>Twelve colours, from 14.00</p></div></li>
      </ol>
    </div>
    <div class="w2thm-strip">
      <div class="w2thm-thumbs">
        <button type="button" class="w2thm-th" aria-label="Show Spindle back chair" aria-current="true"><img src="https://images.pexels.com/photos/28529915/pexels-photo-28529915.jpeg?auto=compress&cs=tinysrgb&w=300" alt="" draggable="false"></button>
        <button type="button" class="w2thm-th" aria-label="Show Three-seat sofa"><img src="https://images.pexels.com/photos/6758245/pexels-photo-6758245.jpeg?auto=compress&cs=tinysrgb&w=300" alt="" draggable="false"></button>
        <button type="button" class="w2thm-th" aria-label="Show Ring vase and globe lamp"><img src="https://images.pexels.com/photos/6952339/pexels-photo-6952339.jpeg?auto=compress&cs=tinysrgb&w=300" alt="" draggable="false"></button>
        <button type="button" class="w2thm-th" aria-label="Show Pleated shade lamp"><img src="https://images.pexels.com/photos/36799079/pexels-photo-36799079.jpeg?auto=compress&cs=tinysrgb&w=300" alt="" draggable="false"></button>
        <button type="button" class="w2thm-th" aria-label="Show Stoneware tableware"><img src="https://images.pexels.com/photos/14341984/pexels-photo-14341984.jpeg?auto=compress&cs=tinysrgb&w=300" alt="" draggable="false"></button>
        <button type="button" class="w2thm-th" aria-label="Show Glazed mugs and plates"><img src="https://images.pexels.com/photos/38243203/pexels-photo-38243203.jpeg?auto=compress&cs=tinysrgb&w=300" alt="" draggable="false"></button>
      </div>
    </div>
    <p class="w2thm-live" aria-live="polite"></p>
  </div>
</section>
<style>
  /* Change these: page colour, ink, slate accent, thumbnail width. */
  .w2thm { --w2thm-bg: #f5f6f8; --w2thm-ink: #1c2430; --w2thm-acc: #3d5a80; --w2thm-th: 150px; }
  .w2thm { background: var(--w2thm-bg); color: var(--w2thm-ink); padding: 48px 16px; font-family: ui-sans-serif, system-ui, sans-serif; overflow: hidden; }
  .w2thm-wrap { max-width: 960px; margin: 0 auto; }
  .w2thm-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
  .w2thm-kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .24em; text-transform: uppercase; color: var(--w2thm-acc); }
  .w2thm-title { margin: 8px 0 0; font-size: clamp(26px, 3.4vw, 36px); font-weight: 650; letter-spacing: -.02em; }
  .w2thm-btns { display: flex; gap: 8px; }
  .w2thm-btn { width: 44px; height: 44px; border-radius: 10px; border: 1px solid #c9d0db; background: #fff; color: var(--w2thm-ink); display: grid; place-items: center; cursor: pointer; }
  .w2thm-btn:hover { border-color: var(--w2thm-acc); }
  .w2thm-btn:disabled { opacity: .35; cursor: default; }
  .w2thm-main { position: relative; overflow: hidden; border-radius: 12px; aspect-ratio: 16 / 9; background: #dfe3ea; touch-action: pan-y; cursor: grab; user-select: none; }
  .w2thm-track, .w2thm-thumbs { display: flex; margin: 0; padding: 0; list-style: none; will-change: transform; }
  .w2thm-track { height: 100%; }
  .w2thm-slide { position: relative; flex: 0 0 100%; height: 100%; }
  .w2thm-slide img { display: block; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
  .w2thm-cap { position: absolute; left: 16px; bottom: 16px; max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 10px; background: rgba(255, 255, 255, .94); box-sizing: border-box; }
  .w2thm-cap h3 { margin: 0; font-size: 17px; font-weight: 650; }
  .w2thm-cap p { margin: 2px 0 0; font-size: 13px; color: #4a5568; }
  .w2thm-strip { margin-top: 14px; overflow: hidden; touch-action: pan-y; cursor: grab; user-select: none; }
  .w2thm-thumbs { gap: 10px; width: max-content; }
  .w2thm-th { flex: none; width: var(--w2thm-th); padding: 0; border: 0; border-radius: 8px; overflow: hidden; background: #dfe3ea; cursor: pointer; opacity: .55; transition: opacity .3s; position: relative; }
  .w2thm-th::after { content: ""; position: absolute; inset: 0; border-radius: 8px; box-shadow: inset 0 0 0 3px var(--w2thm-acc); opacity: 0; transition: opacity .3s; }
  .w2thm-th[aria-current="true"] { opacity: 1; }
  .w2thm-th[aria-current="true"]::after { opacity: 1; }
  .w2thm-th img { display: block; width: 100%; aspect-ratio: 3 / 2; object-fit: cover; pointer-events: none; }
  .w2thm-th:hover { opacity: .85; }
  .w2thm-btn:focus-visible, .w2thm-th:focus-visible, .w2thm-main:focus-visible { outline: 2px solid var(--w2thm-acc); outline-offset: 3px; }
  .w2thm-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  @media (max-width: 640px) { .w2thm { --w2thm-th: 96px; } .w2thm-main { aspect-ratio: 4 / 3; } }
  @media (prefers-reduced-motion: reduce) { .w2thm-th, .w2thm-th::after { transition: none; } }
</style>
<script>
(function(){
/* Change these: friction per frame, rubber band past the ends, idle advance in ms. */
var FRICTION=.93,RUBBER=.3,IDLE=3000;
var R=document.querySelector(".w2thm"),Q=function(s){return R.querySelectorAll(s)},M=Math,F=requestAnimationFrame;
var sl=Q(".w2thm-slide"),th=Q(".w2thm-th"),bt=Q(".w2thm-btn"),lv=Q(".w2thm-live")[0],n=sl.length,I=0,V=1,au=0,mv=0,rm=matchMedia("(prefers-reduced-motion: reduce)").matches;
function cl(i){return M.max(0,M.min(n-1,i))}
/* one small physics routine shared by both rails; snap=1 lands on whole slides, snap=0 coasts and stops */
function rail(vw,tr,snap,cb){var o={x:0,v:0,t:0,dn:0},raf=0,sx,x0,H;
function lim(){return M.min(0,vw.offsetWidth-tr.scrollWidth)}
function loop(){raf=0;var m=lim(),s=vw.offsetWidth,p;
if(!o.dn){if(o.t==null){o.x+=o.v;o.v*=FRICTION;if(o.x>0||o.x<m)o.v*=.6;if(M.abs(o.v)<.5)o.t=snap?-cl(M.round(-o.x/s))*s:M.max(m,M.min(0,o.x))}
if(o.t!=null){o.x=rm?o.t:o.x+(o.t-o.x)*.15;if(M.abs(o.t-o.x)<.5)o.x=o.t}}
p=o.x>0?o.x*RUBBER:o.x<m?m+(o.x-m)*RUBBER:o.x;tr.style.transform="translate3d("+p+"px,0,0)";cb&&cb(p/s);
if(V&&(o.dn||o.t==null||o.x!=o.t))raf=F(loop)}
o.k=function(){raf=raf||F(loop)};o.lim=lim;
vw.onpointerdown=function(e){S();o.dn=1;mv=0;sx=e.clientX;x0=o.x;o.v=0;o.k()};
vw.onpointermove=function(e){if(!o.dn)return;var d=e.clientX-sx;if(M.abs(d)>6&&!mv){mv=1;vw.setPointerCapture(e.pointerId)}o.v=o.v*.5+(x0+d-o.x)*.5;o.x=x0+d;H=e.timeStamp;o.k()};
vw.onpointerup=vw.onpointercancel=function(e){if(!o.dn)return;o.dn=0;if(rm||e.timeStamp-H>100)o.v=0;o.t=null;o.k()};
return o}
var A=rail(Q(".w2thm-main")[0],Q(".w2thm-track")[0],1,function(f){show(cl(M.round(-f)))}),B=rail(Q(".w2thm-strip")[0],Q(".w2thm-thumbs")[0],0);
/* keep the active thumbnail centred in the strip unless someone is dragging the strip */
function centre(i){if(B.dn)return;var t=th[i],w=t.parentNode.parentNode.offsetWidth;B.t=M.max(B.lim(),M.min(0,w/2-t.offsetLeft-t.offsetWidth/2));B.v=0;B.k()}
function show(i){if(i==I)return;th[I].removeAttribute("aria-current");th[i].setAttribute("aria-current","true");sl.forEach(function(e,k){e.ariaHidden=k!=i});I=i;bt[0].disabled=!i;bt[1].disabled=i==n-1;centre(i)}
function go(i,say){A.t=-cl(i)*Q(".w2thm-main")[0].offsetWidth;A.v=0;A.k();if(say)lv.textContent="Piece "+(cl(i)+1)+" of "+n+": "+sl[cl(i)].querySelector("h3").textContent}
function S(){clearTimeout(au);au=-1}
th.forEach(function(t,i){t.addEventListener("click",function(e){if(mv){e.preventDefault();return}S();go(i,1)});t.addEventListener("focus",function(){centre(i)})});
bt.forEach(function(b){b.onclick=function(){S();go(I+ +b.dataset.d,1)}});
R.onkeydown=function(e){var i={ArrowLeft:I-1,ArrowRight:I+1}[e.key];if(i!=null){e.preventDefault();S();go(i,1)}};
R.onpointerenter=S;R.addEventListener("focusin",S);
function tick(){if(au<0)return;if(V)go((I+1)%n);au=setTimeout(tick,IDLE)}
new IntersectionObserver(function(e){V=e[0].isIntersecting;if(V){A.k();B.k()}}).observe(R);
sl.forEach(function(e,k){e.ariaHidden=k>0});
function W(){au=setTimeout(tick,2200)}rm||(document.readyState=="complete"?W():addEventListener("load",W));
})();
</script>

With reduced motion: The main photo and the strip jump straight to the chosen piece; dragging still follows the pointer without a glide.

Running cost: Two rails share one short physics routine and each runs a frame loop only while it is moving.

  • Change thumbnail width with `--w2thm-th` and the strip gap on `.w2thm-thumbs`; the centring maths reads real sizes, so no other edit is needed.
  • Lower `FRICTION` if the free strip coasts too far, or raise `RUBBER` for a looser pull at the ends.
  • Swap the slate accent ring and buttons through `--w2thm-acc`.

Masked Strip Photo Transition Drag Slider

A cabin rental's five stays, with a tall photo on the left and one text card at a time on the right. Drag either side and the text rail coasts on with momentum; when a new card lands, the next photo rises and falls into place through six masked strips that alternate direction. Fits a small hospitality or property site with a few strong pictures.

<section class="w2cab" role="region" aria-roledescription="carousel" aria-label="Hollin Woods cabins">
  <div class="w2cab-wrap">
    <div class="w2cab-stage" tabindex="0">
      <div class="w2cab-layer w2cab-on"><img src="https://images.pexels.com/photos/19231583/pexels-photo-19231583.jpeg?auto=compress&cs=tinysrgb&w=1000" alt="Wooden jetty leading to an old boathouse on a lake, framed by branches" draggable="false"></div>
      <div class="w2cab-layer" aria-hidden="true"><img src="https://images.pexels.com/photos/30550409/pexels-photo-30550409.jpeg?auto=compress&cs=tinysrgb&w=1000" alt="Two wooden cabins beside a forest road under tall pines" draggable="false"></div>
      <div class="w2cab-layer" aria-hidden="true"><img src="https://images.pexels.com/photos/33640978/pexels-photo-33640978.jpeg?auto=compress&cs=tinysrgb&w=1000" alt="Cabin interior with a black wood stove, pine walls and soft curtains" draggable="false"></div>
      <div class="w2cab-layer" aria-hidden="true"><img src="https://images.pexels.com/photos/11148974/pexels-photo-11148974.jpeg?auto=compress&cs=tinysrgb&w=1000" alt="Wooden cabins among snowy trees in winter" draggable="false"></div>
      <div class="w2cab-layer" aria-hidden="true"><img src="https://images.pexels.com/photos/36707272/pexels-photo-36707272.jpeg?auto=compress&cs=tinysrgb&w=1000" alt="A red cabin at the edge of a calm lake below misty green hills" draggable="false"></div>
    </div>
    <div class="w2cab-side">
      <p class="w2cab-kicker">Hollin Woods Cabins</p>
      <h2 class="w2cab-title">Five places to stay quiet for a while</h2>
      <div class="w2cab-view">
        <ol class="w2cab-track">
          <li class="w2cab-item" role="group" aria-roledescription="slide" aria-label="1 of 5"><span class="w2cab-num">01 / 05</span><h3 class="w2cab-name">The boathouse</h3><p class="w2cab-text">A jetty over the water and one room above the old boat bay. Sleeps two, from 140 a night.</p></li>
          <li class="w2cab-item" role="group" aria-roledescription="slide" aria-label="2 of 5"><span class="w2cab-num">02 / 05</span><h3 class="w2cab-name">Pine Road pair</h3><p class="w2cab-text">Two cabins side by side on the forest track, good for families travelling together.</p></li>
          <li class="w2cab-item" role="group" aria-roledescription="slide" aria-label="3 of 5"><span class="w2cab-num">03 / 05</span><h3 class="w2cab-name">The stove room</h3><p class="w2cab-text">Pine walls, a hanging wood stove and a basket of split birch by the door.</p></li>
          <li class="w2cab-item" role="group" aria-roledescription="slide" aria-label="4 of 5"><span class="w2cab-num">04 / 05</span><h3 class="w2cab-name">Winter lodges</h3><p class="w2cab-text">Open December to March, with snowshoes in the porch and the trail starting at the gate.</p></li>
          <li class="w2cab-item" role="group" aria-roledescription="slide" aria-label="5 of 5"><span class="w2cab-num">05 / 05</span><h3 class="w2cab-name">Red cabin</h3><p class="w2cab-text">On the far shore below the hills, reached by a short gravel lane.</p></li>
        </ol>
      </div>
      <div class="w2cab-btns">
        <button class="w2cab-btn" type="button" data-d="-1" aria-label="Previous slide" disabled><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M15 5l-7 7 7 7" fill="none" stroke="currentColor" stroke-width="2"/></svg></button>
        <button class="w2cab-btn" type="button" data-d="1" aria-label="Next slide"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M9 5l7 7-7 7" fill="none" stroke="currentColor" stroke-width="2"/></svg></button>
      </div>
      <p class="w2cab-live" aria-live="polite"></p>
    </div>
  </div>
</section>
<style>
  /* Change these: forest background, cream text, moss accent, strip timing. */
  .w2cab { --w2cab-bg: #1d2720; --w2cab-ink: #efe8d8; --w2cab-acc: #b9c48f; --w2cab-dur: .8s; }
  .w2cab { background: var(--w2cab-bg); color: var(--w2cab-ink); padding: 48px 16px; font-family: ui-sans-serif, system-ui, sans-serif; overflow: hidden; }
  .w2cab-wrap { max-width: 1040px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 32px; align-items: center; }
  @media (min-width: 768px) {
    .w2cab-wrap { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 56px; } }
  .w2cab-stage { position: relative; aspect-ratio: 1 / 1; max-height: 600px; width: 100%; border-radius: 6px; overflow: hidden; background: #2c3a30; touch-action: pan-y; cursor: grab; user-select: none; }
  .w2cab-layer { position: absolute; inset: 0; z-index: 0; }
  .w2cab-strip { position: absolute; top: 0; bottom: 0; overflow: hidden; }
  .w2cab-strip img { position: absolute; top: 0; height: 100%; object-fit: cover; transform: translateY(101%); }
  .w2cab-strip:nth-child(even) img { transform: translateY(-101%); }
  .w2cab-was { z-index: 1; }
  .w2cab-was .w2cab-strip img { transform: none; }
  .w2cab-on { z-index: 2; }
  .w2cab-on .w2cab-strip img, .w2cab-on .w2cab-strip:nth-child(even) img { transform: none; transition: transform var(--w2cab-dur) cubic-bezier(.7, 0, .2, 1); }
  .w2cab-kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .24em; text-transform: uppercase; color: var(--w2cab-acc); }
  .w2cab-title { margin: 12px 0 28px; font: 500 clamp(28px, 3.6vw, 40px)/1.15 Georgia, "Times New Roman", serif; }
  .w2cab-view { overflow: hidden; touch-action: pan-y; cursor: grab; border-top: 1px solid rgba(239, 232, 216, .2); }
  .w2cab-track { display: flex; margin: 0; padding: 0; list-style: none; will-change: transform; }
  .w2cab-item { flex: 0 0 100%; padding: 22px 24px 8px 0; box-sizing: border-box; user-select: none; opacity: .3; transition: opacity .4s; }
  .w2cab-item.w2cab-on { opacity: 1; }
  .w2cab-num { font-size: 12px; font-weight: 600; letter-spacing: .12em; color: var(--w2cab-acc); }
  .w2cab-name { margin: 10px 0 0; font: 500 26px/1.2 Georgia, "Times New Roman", serif; }
  .w2cab-text { margin: 10px 0 0; font-size: 15px; line-height: 1.65; color: #cfc8b8; max-width: 26rem; }
  .w2cab-btns { display: flex; gap: 10px; margin-top: 24px; }
  .w2cab-btn { width: 48px; height: 48px; border-radius: 50%; border: 1px solid rgba(239, 232, 216, .35); background: transparent; color: var(--w2cab-ink); display: grid; place-items: center; cursor: pointer; }
  .w2cab-btn:hover { background: rgba(239, 232, 216, .1); }
  .w2cab-btn:disabled { opacity: .3; cursor: default; }
  .w2cab-btn:focus-visible, .w2cab-stage:focus-visible { outline: 2px solid var(--w2cab-acc); outline-offset: 3px; }
  .w2cab-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  @media (min-width: 768px) { .w2cab-stage { aspect-ratio: 4 / 5; } }
  @media (prefers-reduced-motion: reduce) { .w2cab-on .w2cab-strip img, .w2cab-on .w2cab-strip:nth-child(even) img, .w2cab-item { transition: none; } }
</style>
<script>
(function(){
/* Change these: strips per photo, friction per frame, idle advance in ms. */
var STRIPS=6,FRICTION=.93,IDLE=3000;
var R=document.querySelector(".w2cab"),Q=function(s){return R.querySelectorAll(s)},M=Math,F=requestAnimationFrame;
var st=Q(".w2cab-stage")[0],tr=Q(".w2cab-track")[0],ly=Q(".w2cab-layer"),it=Q(".w2cab-item"),bt=Q(".w2cab-btn"),lv=Q(".w2cab-live")[0];
var n=it.length,rm=matchMedia("(prefers-reduced-motion: reduce)").matches,x=0,v=0,tx=0,raf=0,dn=0,sx,x0,H,I=0,V=1,au=0;
/* cut each photo into strips: every strip is a window onto a full-width copy of the photo */
ly.forEach(function(l){var g=l.firstElementChild;g.remove();for(var i=0;i<STRIPS;i++){var s=document.createElement("div"),c=g.cloneNode();
s.classList.add("w2cab-strip");s.style.cssText="left:"+i*100/STRIPS+"%;width:calc("+100/STRIPS+"% + 1px)";
c.style.cssText="left:"+-i*100+"%;width:"+STRIPS*100+"%;transition-delay:"+i*70+"ms";if(i)c.alt="";l.append(s);s.append(c)}});
function cl(i){return M.max(0,M.min(n-1,i))}
function show(i){if(i==I)return;ly.forEach(function(l,k){l.setAttribute("class","w2cab-layer"+(k==i?" w2cab-on":k==I?" w2cab-was":""));l.ariaHidden=k!=i});
it[I].classList.remove("w2cab-on");it[i].classList.add("w2cab-on");I=i;bt[0].disabled=!i;bt[1].disabled=i==n-1}
function loop(){raf=0;var s=it[0].offsetWidth,m=-(n-1)*s,g,p;
if(!dn){if(tx==null){x+=v;v*=FRICTION;if(x>0||x<m)v*=.6;if(M.abs(v)<.5)tx=cl(M.round(-x/s))}
if(tx!=null){g=-tx*s;x=rm?g:x+(g-x)*.16;if(M.abs(g-x)<.5)x=g}}
p=x>0?x*.3:x<m?m+(x-m)*.3:x;tr.style.transform="translate3d("+p+"px,0,0)";show(cl(M.round(-p/s)));
if(V&&(dn||tx==null||x!=-tx*s))raf=F(loop)}
function k(){raf=raf||F(loop)}
function go(i,say){tx=cl(i);v=0;k();if(say)lv.textContent="Slide "+(tx+1)+": "+it[tx].children[1].textContent}
function S(){clearTimeout(au);au=-1}
function up(e){if(!dn)return;dn=0;if(rm||e.timeStamp-H>100)v=0;tx=null;k()}
/* the photo moves the text rail 1:1 scaled to the rail width */
[st,tr.parentNode].forEach(function(el){var f=1;
el.onpointerdown=function(e){S();dn=1;sx=e.clientX;x0=x;v=0;f=it[0].offsetWidth/el.offsetWidth;el.setPointerCapture(e.pointerId);k()};
el.onpointermove=function(e){if(!dn)return;var d=(e.clientX-sx)*f;v=v*.5+(x0+d-x)*.5;x=x0+d;H=e.timeStamp;k()};
el.onpointerup=el.onpointercancel=up});
bt.forEach(function(b){b.onclick=function(){S();go(I+ +b.dataset.d,1)}});
R.onkeydown=function(e){var i={ArrowLeft:I-1,ArrowRight:I+1}[e.key];if(i!=null){e.preventDefault();S();go(i,1)}};
R.onpointerenter=S;R.addEventListener("focusin",S);
function tick(){if(au<0)return;if(V)go((I+1)%n);au=setTimeout(tick,IDLE)}
new IntersectionObserver(function(e){V=e[0].isIntersecting;V&&k()}).observe(R);
it[0].classList.add("w2cab-on");
function A(){au=setTimeout(tick,2200)}rm||(document.readyState=="complete"?A():addEventListener("load",A));
})();
</script>

With reduced motion: The next cabin photo and its text appear at once, with no strip wipe and no coasting rail.

Running cost: Strips move with CSS transform transitions on their own layers; the script only runs while the rail is dragged or settling.

  • Set `STRIPS` for more or fewer bands, and the stagger in milliseconds where each strip's `transition-delay` is written.
  • Tune the wipe with `--w2cab-dur` and the cubic-bezier on `.w2cab-on .w2cab-strip img`.
  • Change the forest and moss palette through `--w2cab-bg`, `--w2cab-ink` and `--w2cab-acc`.

Momentum Card Rail With Progress Bar

A potter's studio rail of tall photo cards on warm paper. Pull it and the cards keep travelling after you let go, slow down, then ease onto the nearest card edge. A thin bar under the rail grows with scaleX as you get closer to the last piece, with a slide counter beside it. Suits a shop or maker showing a handful of pieces.

<section class="w1rai" role="region" aria-roledescription="carousel" aria-label="Pieces from the Fennick Clay Studio">
  <div class="w1rai-head">
    <div>
      <p class="w1rai-kick">Fennick Clay Studio</p>
      <h2 class="w1rai-title">From the wheel this month</h2>
    </div>
    <div class="w1rai-nav">
      <button class="w1rai-btn w1rai-prev" type="button" aria-label="Previous slide"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M15 5l-7 7 7 7" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
      <button class="w1rai-btn w1rai-next" type="button" aria-label="Next slide"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M9 5l7 7-7 7" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
    </div>
  </div>
  <div class="w1rai-view">
    <div class="w1rai-track">
      <div class="w1rai-slide" role="group" aria-roledescription="slide" aria-label="1 of 6"><a class="w1rai-card" href="#" draggable="false"><span class="w1rai-ph"><img src="https://images.pexels.com/photos/29286721/pexels-photo-29286721.jpeg?auto=compress&cs=tinysrgb&w=800" alt="Rows of unglazed bottle vases drying on a workshop rack" width="640" height="800" draggable="false"></span><span class="w1rai-name">Bisque bottle vases</span><span class="w1rai-note">Drying on the rack before glaze</span></a></div>
      <div class="w1rai-slide" role="group" aria-roledescription="slide" aria-label="2 of 6"><a class="w1rai-card" href="#" draggable="false"><span class="w1rai-ph"><img src="https://images.pexels.com/photos/15122651/pexels-photo-15122651.jpeg?auto=compress&cs=tinysrgb&w=800" alt="A potter in an apron using a small torch on a tall clay vase" width="640" height="800" draggable="false"></span><span class="w1rai-name">Firming with a torch</span><span class="w1rai-note">A tall vase before trimming</span></a></div>
      <div class="w1rai-slide" role="group" aria-roledescription="slide" aria-label="3 of 6"><a class="w1rai-card" href="#" draggable="false"><span class="w1rai-ph"><img src="https://images.pexels.com/photos/16124848/pexels-photo-16124848.jpeg?auto=compress&cs=tinysrgb&w=800" alt="Two white vases painted with pink and blue flowers on a tree stump" width="640" height="800" draggable="false"></span><span class="w1rai-name">Pink and blue florals</span><span class="w1rai-note">A pair of painted bud vases</span></a></div>
      <div class="w1rai-slide" role="group" aria-roledescription="slide" aria-label="4 of 6"><a class="w1rai-card" href="#" draggable="false"><span class="w1rai-ph"><img src="https://images.pexels.com/photos/32490730/pexels-photo-32490730.jpeg?auto=compress&cs=tinysrgb&w=800" alt="A row of jars glazed with red and blue patterns on a wooden shelf" width="640" height="800" draggable="false"></span><span class="w1rai-name">Patterned jars</span><span class="w1rai-note">Red and cobalt glaze, shop shelf</span></a></div>
      <div class="w1rai-slide" role="group" aria-roledescription="slide" aria-label="5 of 6"><a class="w1rai-card" href="#" draggable="false"><span class="w1rai-ph"><img src="https://images.pexels.com/photos/18449692/pexels-photo-18449692.jpeg?auto=compress&cs=tinysrgb&w=800" alt="Large terracotta urns and vases standing among green palm leaves" width="640" height="800" draggable="false"></span><span class="w1rai-name">Terracotta urns</span><span class="w1rai-note">Unglazed, for the garden room</span></a></div>
      <div class="w1rai-slide" role="group" aria-roledescription="slide" aria-label="6 of 6"><a class="w1rai-card" href="#" draggable="false"><span class="w1rai-ph"><img src="https://images.pexels.com/photos/37821669/pexels-photo-37821669.jpeg?auto=compress&cs=tinysrgb&w=800" alt="A potter seated beside two brown clay vases in his workshop" width="640" height="800" draggable="false"></span><span class="w1rai-name">A wheel-thrown pair</span><span class="w1rai-note">Two brown vases with their maker</span></a></div>
    </div>
  </div>
  <div class="w1rai-foot">
    <span class="w1rai-bar" aria-hidden="true"><span class="w1rai-fill"></span></span>
    <span class="w1rai-count" aria-hidden="true">01 / 06</span>
  </div>
  <p class="w1rai-live" aria-live="polite"></p>
</section>
<style>
  /* Change these: paper colour, ink colour, clay accent, card width. */
  .w1rai { --w1rai-paper: #f3ede4; --w1rai-ink: #2b2420; --w1rai-clay: #9a4a28; --w1rai-card: clamp(230px, 27vw, 310px); }
  .w1rai, .w1rai * { box-sizing: border-box; }
  .w1rai { position: relative; overflow: hidden; background: var(--w1rai-paper); color: var(--w1rai-ink); padding: 64px 0 56px; font-family: ui-sans-serif, system-ui, sans-serif; }
  .w1rai-head, .w1rai-foot { max-width: 72rem; margin: 0 auto; padding: 0 24px; display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
  .w1rai-kick { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .24em; text-transform: uppercase; color: var(--w1rai-clay); }
  .w1rai-title { margin: 12px 0 0; font-family: ui-serif, Georgia, serif; font-size: clamp(28px, 4vw, 44px); font-weight: 500; line-height: 1.1; letter-spacing: -.01em; }
  .w1rai-nav { display: flex; gap: 10px; }
  .w1rai-btn { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 999px; border: 1px solid rgba(43, 36, 32, .25); background: transparent; color: var(--w1rai-ink); cursor: pointer; transition: background-color .2s, color .2s, opacity .2s; }
  .w1rai-btn:hover:not(:disabled) { background: var(--w1rai-ink); color: var(--w1rai-paper); }
  .w1rai-btn:disabled { opacity: .35; cursor: default; }
  .w1rai-btn:focus-visible, .w1rai-card:focus-visible { outline: 2px solid var(--w1rai-clay); outline-offset: 4px; }
  .w1rai-view { margin-top: 40px; overflow: hidden; }
  .w1rai-track { position: relative; display: flex; gap: 20px; width: max-content; padding: 4px max(24px, calc((100vw - 72rem) / 2 + 24px)) 8px; touch-action: pan-y; cursor: grab; user-select: none; -webkit-user-select: none; will-change: transform; }
  .w1rai.w1rai-drag .w1rai-track { cursor: grabbing; }
  .w1rai-slide { width: var(--w1rai-card); flex: none; }
  .w1rai-card { display: block; color: inherit; text-decoration: none; border-radius: 6px; -webkit-user-drag: none; }
  .w1rai-ph { position: relative; display: block; aspect-ratio: 4 / 5; overflow: hidden; border-radius: 6px; background: #e2d8ca; box-shadow: 0 1px 2px rgba(43, 36, 32, .08), 0 14px 30px -18px rgba(43, 36, 32, .45); }
  .w1rai-ph img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .6s cubic-bezier(.2, .7, .2, 1); pointer-events: none; }
  .w1rai-card:hover img, .w1rai-card:focus-visible img { transform: scale(1.04); }
  .w1rai-name { display: block; margin-top: 14px; font-family: ui-serif, Georgia, serif; font-size: 19px; }
  .w1rai-note { display: block; margin-top: 4px; font-size: 14px; color: #5e534b; }
  .w1rai-foot { margin-top: 32px; align-items: center; }
  .w1rai-bar { position: relative; flex: 1; height: 2px; max-width: 420px; background: rgba(43, 36, 32, .15); overflow: hidden; }
  .w1rai-fill { position: absolute; inset: 0; background: var(--w1rai-ink); transform-origin: 0 50%; transform: scaleX(.3); }
  .w1rai-count { font-size: 13px; font-variant-numeric: tabular-nums; letter-spacing: .08em; color: #5e534b; }
  .w1rai-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  @media (max-width: 560px) { .w1rai-btn { width: 44px; height: 44px; } .w1rai-head { align-items: flex-start; flex-direction: column; } }
  @media (prefers-reduced-motion: reduce) { .w1rai-ph img, .w1rai-btn { transition: none; } .w1rai-card:hover img { transform: none; } }
</style>
<script>
(function(){
/* Change these: glide friction per frame (nearer 1 glides further), snap spring, its damping, idle advance (ms). */
var FRICTION=.93,SPRING=.1,DAMP=.7,IDLE=4000;
function init(R){
var q=s=>R.querySelector(".w1rai-"+s),V=q("view"),T=q("track"),F=q("fill"),C=q("count"),L=q("live"),P=q("prev"),N=q("next"),
S=[...R.querySelectorAll(".w1rai-slide")],n=S.length,rm=matchMedia("(prefers-reduced-motion: reduce)").matches,
x=0,v=0,min=0,pts=[0],i=0,mode=0,tgt=0,raf=0,fr=0,d=0,moved=0,h=[],vis=1,idle=0,
ac=new AbortController(),on=(el,t,f,c)=>el.addEventListener(t,f,{signal:ac.signal,capture:!!c}),
M=Math,A=M.abs,cl=(a,lo,hi)=>M.max(lo,M.min(hi,a)),rq=requestAnimationFrame,ca=cancelAnimationFrame,
z=k=>(k<10?"0":"")+k,last=()=>pts.length-1,num=k=>k==last()?n:k+1,
near=p=>{var b=0;pts.forEach((t,k)=>{if(A(t-p)<A(pts[b]-p))b=k});return b};
function measure(){min=M.min(0,V.clientWidth-T.offsetWidth);pts=[0];
S.forEach(s=>{var p=M.max(min,S[0].offsetLeft-s.offsetLeft);if(pts[last()]-p>1)pts.push(p)});
x=cl(x,min,0);draw()}
function draw(){T.style.transform="translate3d("+x+"px,0,0)";i=near(x);
var f=V.clientWidth/T.offsetWidth;
/* the bar grows with scaleX, never width */
F.style.transform="scaleX("+(f+(1-f)*(min?cl(x/min,0,1):1))+")";
C.textContent=z(num(i))+" / "+z(n);P.disabled=x>-1;N.disabled=x<min+1}
function loop(){
/* mode 1 = coasting with friction, mode 2 = spring onto the chosen slide */
if(mode==1){x+=v;v*=x>0||x<min?.6:FRICTION;if(A(v)<3){mode=2;tgt=pts[near(x+v*9)]}}
else{v=(v+(tgt-x)*SPRING)*DAMP;x+=v;if(A(tgt-x)<.4&&A(v)<.4){x=tgt;mode=0}}
draw();raf=mode&&vis?rq(loop):0}
function run(){if(!raf&&mode&&vis)raf=rq(loop)}
function go(k,say){k=cl(k,0,last());tgt=pts[k];
if(rm){mode=0;x=tgt;draw()}else{mode=2;run()}
if(say)L.textContent="Slide "+num(k)+" of "+n}
function stop(){clearInterval(idle)}
on(T,"pointerdown",e=>{if(e.button)return;stop();ca(raf);raf=mode=moved=0;d={p:e.clientX,s:x,id:e.pointerId};h=[[e.timeStamp,x]]});
on(T,"pointermove",e=>{if(!d)return;var m=d.s+e.clientX-d.p,t=e.timeStamp;
if(!moved&&A(m-d.s)>6){moved=1;T.setPointerCapture(d.id)}
if(!moved)return;
/* rubber band past either end */
x=m>0?m*.35:m<min?min+(m-min)*.35:m;
h.push([t,x]);while(h.length>2&&t-h[0][0]>100)h.shift();
if(!fr)fr=rq(()=>{fr=0;draw()})});
function up(e){if(!d)return;d=0;if(!moved)return;
var a=h[0],b=h[h.length-1],t=b[0]-a[0];
/* release speed from the last 100 ms of moves */
v=t>0&&e.timeStamp-b[0]<80?(b[1]-a[1])/t*16.7:0;
if(rm)go(near(x));else{mode=1;run()}}
on(T,"pointerup",up);on(T,"pointercancel",up);
/* a drag is not a click on the card link */
on(T,"click",e=>{if(moved){e.preventDefault();e.stopPropagation();moved=0}},1);
on(P,"click",()=>{stop();go(i-1,1)});on(N,"click",()=>{stop();go(i+1,1)});
on(R,"keydown",e=>{var k={ArrowLeft:-1,ArrowRight:1}[e.key];if(k){e.preventDefault();stop();go(i+k,1)}});
on(R,"focusin",e=>{stop();V.scrollLeft=0;var s=e.target.closest(".w1rai-slide");if(s)go(S.indexOf(s))});
on(R,"pointerenter",stop);
var io=new IntersectionObserver(en=>{vis=en[0].isIntersecting;if(vis)run();else{ca(raf);raf=0}});
on(window,"resize",measure);io.observe(R);measure();
/* idle demo: one slide every IDLE ms until the pointer arrives or anything is pressed */
if(!rm)idle=setInterval(()=>vis&&!document.hidden&&go(i<last()?i+1:0),IDLE);
return()=>{ac.abort();io.disconnect();stop();ca(raf);ca(fr)}}
var R=document.querySelector(".w1rai");if(R)init(R);
})();
</script>

With reduced motion: Dragging still follows the pointer, but on release and on every button or key press the rail jumps straight to its slide with no glide.

Running cost: One transform on the track and one scaleX on the bar, written once per frame only while a drag or settle is running.

  • Raise `FRICTION` towards 0.96 for a longer glide, or lower it to 0.88 so the rail stops sooner.
  • Change the card width with `--w1rai-card` and the gap with `gap` on `.w1rai-track`.
  • Recolour through `--w1rai-paper`, `--w1rai-ink` and `--w1rai-clay`.

Slider With Draggable Scrubber Handle

A bakery's working day told in six time cards, with a pill handle on a line underneath. Drag the cards and they coast with momentum while the handle tracks along; drag the handle instead and the cards scrub through the day under it, then settle on the closest card when you let go. Fits timelines, process steps and dated histories.

<section class="w1scr" role="region" aria-roledescription="carousel" aria-label="A day at Pell Street Bakery">
  <div class="w1scr-head">
    <div>
      <p class="w1scr-kick">Pell Street Bakery</p>
      <h2 class="w1scr-title">One day at the bench</h2>
    </div>
    <div class="w1scr-nav">
      <button class="w1scr-btn w1scr-prev" type="button" aria-label="Previous slide"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M15 5l-7 7 7 7" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
      <button class="w1scr-btn w1scr-next" type="button" aria-label="Next slide"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M9 5l7 7-7 7" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
    </div>
  </div>
  <div class="w1scr-view">
    <div class="w1scr-track">
      <article class="w1scr-slide" role="group" aria-roledescription="slide" aria-label="1 of 6" data-name="04:30 Ovens on"><p class="w1scr-time">04:30</p><h3 class="w1scr-name">Ovens on</h3><p class="w1scr-text">The deck oven takes an hour to reach heat, so the first job is lighting it and feeding the rye starter.</p></article>
      <article class="w1scr-slide" role="group" aria-roledescription="slide" aria-label="2 of 6" data-name="05:45 Shaping"><p class="w1scr-time">05:45</p><h3 class="w1scr-name">Shaping</h3><p class="w1scr-text">Yesterday's dough comes out of the cold room and is shaped into batards and long tin loaves.</p></article>
      <article class="w1scr-slide" role="group" aria-roledescription="slide" aria-label="3 of 6" data-name="07:00 Doors open"><p class="w1scr-time">07:00</p><h3 class="w1scr-name">Doors open</h3><p class="w1scr-text">The first bake goes on the racks by the window while the coffee machine warms up.</p></article>
      <article class="w1scr-slide" role="group" aria-roledescription="slide" aria-label="4 of 6" data-name="10:30 Pastry"><p class="w1scr-time">10:30</p><h3 class="w1scr-name">Pastry</h3><p class="w1scr-text">Laminated dough for tomorrow's croissants is rolled, folded and rested three times.</p></article>
      <article class="w1scr-slide" role="group" aria-roledescription="slide" aria-label="5 of 6" data-name="13:00 Second bake"><p class="w1scr-time">13:00</p><h3 class="w1scr-name">Second bake</h3><p class="w1scr-text">Focaccia and seeded rolls for the lunch trade, topped with whatever the market had.</p></article>
      <article class="w1scr-slide" role="group" aria-roledescription="slide" aria-label="6 of 6" data-name="16:00 Mix for tomorrow"><p class="w1scr-time">16:00</p><h3 class="w1scr-name">Mix for tomorrow</h3><p class="w1scr-text">Flour, water and starter are mixed, then left to rise slowly in the cold overnight.</p></article>
    </div>
  </div>
  <div class="w1scr-scrub">
    <div class="w1scr-bar"><span class="w1scr-line" aria-hidden="true"></span><span class="w1scr-knob" role="slider" tabindex="0" aria-label="Time of day" aria-valuemin="1" aria-valuemax="6" aria-valuenow="1" aria-valuetext="04:30 Ovens on"><span class="w1scr-grip" aria-hidden="true"></span></span></div>
    <div class="w1scr-ticks" aria-hidden="true"><span class="w1scr-tick">04:30</span><span class="w1scr-tick">05:45</span><span class="w1scr-tick">07:00</span><span class="w1scr-tick">10:30</span><span class="w1scr-tick">13:00</span><span class="w1scr-tick">16:00</span></div>
  </div>
  <p class="w1scr-live" aria-live="polite"></p>
</section>
<style>
  /* Change these: page colour, ink, accent for the handle, card width. */
  .w1scr { --w1scr-bg: #f7f8fa; --w1scr-ink: #1e293b; --w1scr-accent: #334155; --w1scr-card: clamp(250px, 30vw, 340px); }
  .w1scr, .w1scr * { box-sizing: border-box; }
  .w1scr { position: relative; overflow: hidden; background: var(--w1scr-bg); color: var(--w1scr-ink); padding: 64px 0 56px; font-family: ui-sans-serif, system-ui, sans-serif; }
  .w1scr-head, .w1scr-scrub { max-width: 72rem; margin: 0 auto; padding: 0 24px; }
  .w1scr-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
  .w1scr-kick { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .22em; text-transform: uppercase; color: #475569; }
  .w1scr-title { margin: 12px 0 0; font-size: clamp(28px, 4vw, 42px); font-weight: 650; letter-spacing: -.025em; line-height: 1.1; }
  .w1scr-nav { display: flex; gap: 8px; }
  .w1scr-btn { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 10px; border: 1px solid #cbd5e1; background: #fff; color: var(--w1scr-ink); cursor: pointer; transition: opacity .2s, border-color .2s; }
  .w1scr-btn:hover:not(:disabled) { border-color: var(--w1scr-ink); }
  .w1scr-btn:disabled { opacity: .4; cursor: default; }
  .w1scr-btn:focus-visible, .w1scr-knob:focus-visible { outline: 2px solid var(--w1scr-ink); outline-offset: 3px; }
  .w1scr-view { margin-top: 36px; overflow: hidden; }
  .w1scr-track { display: flex; gap: 16px; width: max-content; padding: 6px calc(100vw - var(--w1scr-card) - max(24px, calc((100vw - 72rem) / 2 + 24px))) 10px max(24px, calc((100vw - 72rem) / 2 + 24px)); touch-action: pan-y; cursor: grab; user-select: none; -webkit-user-select: none; will-change: transform; }
  .w1scr-track:active { cursor: grabbing; }
  .w1scr-slide { width: var(--w1scr-card); flex: none; min-height: 230px; padding: 26px; border-radius: 14px; background: #fff; border: 1px solid #e2e8f0; box-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 12px 24px -16px rgba(15, 23, 42, .18); }
  .w1scr-time { margin: 0; font-size: 34px; font-weight: 300; font-variant-numeric: tabular-nums; letter-spacing: -.02em; color: #475569; }
  .w1scr-name { margin: 18px 0 0; font-size: 19px; font-weight: 650; }
  .w1scr-text { margin: 8px 0 0; font-size: 15px; line-height: 1.6; color: #475569; }
  .w1scr-scrub { margin-top: 34px; }
  .w1scr-bar { position: relative; height: 44px; }
  .w1scr-line { position: absolute; left: 0; right: 0; top: 21px; height: 2px; border-radius: 2px; background: #cbd5e1; }
  .w1scr-knob { position: absolute; left: 0; top: 0; display: grid; place-items: center; width: 64px; height: 44px; border-radius: 999px; background: var(--w1scr-accent); cursor: grab; touch-action: none; will-change: transform; box-shadow: 0 6px 14px -6px rgba(15, 23, 42, .5); }
  .w1scr-grip { width: 18px; height: 10px; border-left: 2px solid #e2e8f0; border-right: 2px solid #e2e8f0; box-shadow: inset 2px 0 0 transparent, inset -8px 0 0 -6px #e2e8f0; }
  .w1scr-ticks { display: flex; justify-content: space-between; margin-top: 10px; padding: 0 14px; font-size: 12px; font-variant-numeric: tabular-nums; color: #475569; }
  .w1scr-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  @media (max-width: 560px) { .w1scr-tick:nth-child(even) { visibility: hidden; } }
  @media (prefers-reduced-motion: reduce) { .w1scr-btn { transition: none; } }
</style>
<script>
(function(){
/* Change these: glide friction, snap spring, damping, idle advance (ms). */
var FRICTION=.93,SPRING=.1,DAMP=.7,IDLE=4000;
function init(R){
var q=s=>R.querySelector(".w1scr-"+s),V=q("view"),T=q("track"),B=q("bar"),H=q("knob"),L=q("live"),P=q("prev"),N=q("next"),
S=[...R.querySelectorAll(".w1scr-slide")],n=S.length,rm=matchMedia("(prefers-reduced-motion: reduce)").matches,
x=0,v=0,min=0,pts=[0],i=0,mode=0,tgt=0,raf=0,fr=0,d=0,moved=0,h=[],vis=1,idle=0,
ac=new AbortController(),on=(el,t,f,c)=>el.addEventListener(t,f,{signal:ac.signal,capture:!!c}),
M=Math,A=M.abs,cl=(a,lo,hi)=>M.max(lo,M.min(hi,a)),rq=requestAnimationFrame,ca=cancelAnimationFrame,
near=p=>{var b=0;pts.forEach((t,k)=>{if(A(t-p)<A(pts[b]-p))b=k});return b},
room=()=>B.clientWidth-H.offsetWidth,paint=()=>{if(!fr)fr=rq(()=>{fr=0;draw()})};
function ms(){pts=S.map(s=>S[0].offsetLeft-s.offsetLeft);min=pts[n-1];x=pts[i];draw()}
function draw(){T.style.transform="translate3d("+x+"px,0,0)";i=near(x);
/* the handle sits at the same fraction along its bar as the track along its run */
H.style.transform="translate3d("+room()*cl(x/min,0,1)+"px,0,0)";
H.setAttribute("aria-valuenow",i+1);H.setAttribute("aria-valuetext",S[i].dataset.name);
P.disabled=!i;N.disabled=i==n-1}
function loop(){
if(mode==1){x+=v;v*=x>0||x<min?.6:FRICTION;if(A(v)<3){mode=2;tgt=pts[near(x+v*9)]}}
else{v=(v+(tgt-x)*SPRING)*DAMP;x+=v;if(A(tgt-x)<.4&&A(v)<.4){x=tgt;mode=0}}
draw();raf=mode&&vis?rq(loop):0}
function run(){if(!raf&&mode&&vis)raf=rq(loop)}
function go(k,say){k=cl(k,0,n-1);tgt=pts[k];
if(rm){mode=0;x=tgt;draw()}else{mode=2;run()}
if(say)L.textContent="Slide "+(k+1)+" of "+n}
function stop(){clearInterval(idle)}
function grab(e){stop();ca(raf);raf=mode=moved=0;d={p:e.clientX,s:x,id:e.pointerId,k:e.currentTarget==H};h=[[e.timeStamp,x]];if(d.k)H.setPointerCapture(e.pointerId)}
on(T,"pointerdown",e=>{if(!e.button)grab(e)});on(H,"pointerdown",grab);
on(R,"pointermove",e=>{if(!d)return;var dx=e.clientX-d.p,m=d.s+(d.k?dx*min/room():dx),t=e.timeStamp;
if(!moved&&A(dx)>6){moved=1;d.k||T.setPointerCapture(d.id)}
if(!moved)return;
/* the track follows a drag on the cards, and moves the opposite way to a drag on the handle */
x=m>0?m*.35:m<min?min+(m-min)*.35:m;
h.push([t,x]);while(h.length>2&&t-h[0][0]>100)h.shift();paint()});
function up(e){if(!d)return;var k=d.k;d=0;if(!moved)return;
var a=h[0],b=h[h.length-1],t=b[0]-a[0];
v=!k&&t>0&&e.timeStamp-b[0]<80?(b[1]-a[1])/t*16.7:0;
if(rm)go(near(x));else{mode=1;run()}}
on(R,"pointerup",up);on(R,"pointercancel",up);
on(P,"click",()=>{stop();go(i-1,1)});on(N,"click",()=>{stop();go(i+1,1)});
on(R,"keydown",e=>{var k={ArrowLeft:-1,ArrowRight:1}[e.key];if(k){e.preventDefault();stop();go(i+k,1)}});
on(R,"focusin",e=>{stop();V.scrollLeft=0;var s=e.target.closest(".w1scr-slide");if(s)go(S.indexOf(s))});
on(R,"pointerenter",stop);
var io=new IntersectionObserver(en=>{vis=en[0].isIntersecting;if(vis)run();else{ca(raf);raf=0}});
on(window,"resize",ms);io.observe(R);ms();
/* idle demo: one slide every IDLE ms until the pointer arrives or anything is pressed */
if(!rm)idle=setInterval(()=>vis&&!document.hidden&&go(i<n-1?i+1:0),IDLE);
return()=>{ac.abort();io.disconnect();stop();ca(raf);ca(fr)}}
var R=document.querySelector(".w1scr");if(R)init(R);
})();
</script>

With reduced motion: Cards and handle still follow a drag one to one, then land on the nearest card at once; buttons and keys jump with no glide.

Running cost: Two transforms, one for the track and one for the handle, are written once per frame during a drag or settle and never at rest.

  • Change the handle size on `.w1scr-knob` and its colour with `--w1scr-accent`.
  • Edit the six `article` cards and the matching `.w1scr-tick` labels under the line together.
  • Lower `FRICTION` so a flick on the cards stops sooner, or raise `SPRING` for a quicker landing.

Testimonial Slider With Big Quote and Drag

Client notes for a furniture restorer, set large in a serif on a terracotta-tinted panel, one note at a time. Pulling sideways drags the quote with your finger while it fades out and the next fades in, and a quick flick carries on to the following note. Heading, counter and arrows sit in a side column that stacks above on phones.

<section class="w1quo" role="region" aria-roledescription="carousel" aria-label="Notes from Calloway Joinery clients">
  <div class="w1quo-wrap">
    <div class="w1quo-side">
      <p class="w1quo-kick">Calloway Joinery</p>
      <h2 class="w1quo-title">Furniture that came back to us</h2>
      <div class="w1quo-ctl">
        <button class="w1quo-btn w1quo-prev" type="button" aria-label="Previous slide"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M19 12H5m6-6l-6 6 6 6" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
        <span class="w1quo-count" aria-hidden="true">01 / 04</span>
        <button class="w1quo-btn w1quo-next" type="button" aria-label="Next slide"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M5 12h14m-6-6l6 6-6 6" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
      </div>
    </div>
    <div class="w1quo-view">
      <svg class="w1quo-mark" viewBox="0 0 64 48" aria-hidden="true"><path d="M0 48V28C0 12 8 3 24 0l3 6C17 9 13 15 13 22h11v26H0zm37 0V28c0-16 8-25 24-28l3 6c-10 3-14 9-14 16h11v26H37z" fill="currentColor"/></svg>
      <div class="w1quo-track">
      <figure class="w1quo-slide" role="group" aria-roledescription="slide" aria-label="1 of 4"><div class="w1quo-inner"><blockquote class="w1quo-q"><p>The leaf of my grandmother's table had split along the grain. It came back with the crack closed, the old pegs reused, and the scratch from my uncle's toy car left alone, as I asked.</p></blockquote><figcaption class="w1quo-by"><span class="w1quo-av" aria-hidden="true">IH</span><span><span class="w1quo-nm">Imogen Hale</span><span class="w1quo-it">Oak dining table, Frome</span></span></figcaption></div></figure>
      <figure class="w1quo-slide" role="group" aria-roledescription="slide" aria-label="2 of 4"><div class="w1quo-inner"><blockquote class="w1quo-q"><p>We brought in six chairs that did not match and had wobbled for years. Each one now sits flat on the kitchen tiles and they share one new rush seat pattern.</p></blockquote><figcaption class="w1quo-by"><span class="w1quo-av" aria-hidden="true">TW</span><span><span class="w1quo-nm">Tomasz Wilk</span><span class="w1quo-it">Kitchen chairs, Bath</span></span></figcaption></div></figure>
      <figure class="w1quo-slide" role="group" aria-roledescription="slide" aria-label="3 of 4"><div class="w1quo-inner"><blockquote class="w1quo-q"><p>They talked me through French polish against oil before touching the bureau, then sent photos as the layers built up. It looks like it did in the old family pictures.</p></blockquote><figcaption class="w1quo-by"><span class="w1quo-av" aria-hidden="true">RA</span><span><span class="w1quo-nm">Ruth Adeyemi</span><span class="w1quo-it">Walnut bureau, Bristol</span></span></figcaption></div></figure>
      <figure class="w1quo-slide" role="group" aria-roledescription="slide" aria-label="4 of 4"><div class="w1quo-inner"><blockquote class="w1quo-q"><p>A drawer that had not opened since we moved now slides on new oak runners. The brass handles were cleaned, not replaced, which was the part I cared about.</p></blockquote><figcaption class="w1quo-by"><span class="w1quo-av" aria-hidden="true">CR</span><span><span class="w1quo-nm">Callum Rees</span><span class="w1quo-it">Chest of drawers, Wells</span></span></figcaption></div></figure>
      </div>
    </div>
  </div>
  <p class="w1quo-live" aria-live="polite"></p>
</section>
<style>
  /* Change these: background, text, accent for the quote mark and initials, quote size. */
  .w1quo { --w1quo-bg: #f1e3d6; --w1quo-text: #3a2119; --w1quo-accent: #b4532f; --w1quo-size: clamp(22px, 2.6vw, 32px); }
  .w1quo, .w1quo * { box-sizing: border-box; }
  .w1quo { position: relative; overflow: hidden; background: var(--w1quo-bg); color: var(--w1quo-text); padding: 72px 24px; font-family: ui-sans-serif, system-ui, sans-serif; }
  .w1quo-wrap { max-width: 72rem; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2.2fr); gap: 56px; align-items: start; }
  .w1quo-kick { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .22em; text-transform: uppercase; color: #8e3f22; }
  .w1quo-title { margin: 14px 0 0; font-size: clamp(26px, 3vw, 36px); font-weight: 600; line-height: 1.15; letter-spacing: -.015em; }
  .w1quo-ctl { display: flex; align-items: center; gap: 14px; margin-top: 32px; }
  .w1quo-count { font-size: 14px; font-variant-numeric: tabular-nums; letter-spacing: .06em; }
  .w1quo-btn { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 999px; border: 1.5px solid var(--w1quo-text); background: transparent; color: inherit; cursor: pointer; transition: background-color .2s, color .2s, opacity .2s; }
  .w1quo-btn:hover:not(:disabled) { background: var(--w1quo-text); color: var(--w1quo-bg); }
  .w1quo-btn:disabled { opacity: .3; cursor: default; }
  .w1quo-btn:focus-visible { outline: 2px solid var(--w1quo-accent); outline-offset: 4px; }
  .w1quo-view { position: relative; overflow: hidden; padding-top: 52px; }
  .w1quo-mark { position: absolute; top: 0; left: 0; width: 64px; height: 48px; color: var(--w1quo-accent); }
  .w1quo-track { display: flex; touch-action: pan-y; cursor: grab; user-select: none; -webkit-user-select: none; will-change: transform; }
  .w1quo-track:active { cursor: grabbing; }
  .w1quo-slide { flex: 0 0 100%; margin: 0; will-change: opacity; }
  .w1quo-inner { padding-right: 8%; }
  .w1quo-q { margin: 0; }
  .w1quo-q p { margin: 0; font-family: ui-serif, Georgia, serif; font-size: var(--w1quo-size); line-height: 1.38; letter-spacing: -.005em; }
  .w1quo-by { display: flex; align-items: center; gap: 14px; margin-top: 28px; }
  .w1quo-av { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 999px; background: var(--w1quo-accent); color: #fff7ef; font-size: 14px; font-weight: 700; }
  .w1quo-nm { display: block; font-size: 15px; font-weight: 600; }
  .w1quo-it { display: block; font-size: 14px; color: #6b4a3d; }
  .w1quo-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  @media (max-width: 760px) { .w1quo-wrap { grid-template-columns: 1fr; gap: 28px; } .w1quo-ctl { margin-top: 20px; } }
  @media (prefers-reduced-motion: reduce) { .w1quo-btn { transition: none; } }
</style>
<script>
(function(){
/* Change these: glide friction, snap spring, damping, how fast a quote fades as it leaves (higher = sooner), idle advance (ms). */
var FRICTION=.9,SPRING=.07,DAMP=.76,FADE=1.7,IDLE=4500;
function init(R){
var q=s=>R.querySelector(".w1quo-"+s),V=q("view"),T=q("track"),C=q("count"),L=q("live"),P=q("prev"),N=q("next"),
S=[...R.querySelectorAll(".w1quo-slide")],n=S.length,rm=matchMedia("(prefers-reduced-motion: reduce)").matches,
x=0,v=0,lo=0,hi=0,pts=[],i=0,mode=0,tgt=0,raf=0,fr=0,d=0,moved=0,h=[],vis=1,idle=0,
ac=new AbortController(),on=(el,t,f,c)=>el.addEventListener(t,f,{signal:ac.signal,capture:!!c}),
M=Math,A=M.abs,cl=(a,b,c)=>M.max(b,M.min(c,a)),rq=requestAnimationFrame,ca=cancelAnimationFrame,
near=p=>{var b=0;pts.forEach((t,k)=>{if(A(t-p)<A(pts[b]-p))b=k});return b};
function ms(){pts=S.map(s=>-s.offsetLeft);hi=0;lo=pts[n-1];x=pts[i];draw()}
function draw(){T.style.transform="translate3d("+x+"px,0,0)";i=near(x);
/* a quote fades out as it moves off centre while the next fades in */
S.forEach((s,k)=>{var e=A(x-pts[k])/s.offsetWidth;s.style.opacity=M.max(0,1-e*FADE)});
C.textContent=`0${i+1} / 0${n}`;
P.disabled=!i;N.disabled=i==n-1}
function loop(){
if(mode==1){x+=v;v*=x>hi||x<lo?.6:FRICTION;if(A(v)<3){mode=2;tgt=pts[near(x+v*9)]}}
else{v=(v+(tgt-x)*SPRING)*DAMP;x+=v;if(A(tgt-x)<.4&&A(v)<.4){x=tgt;mode=0}}
draw();raf=mode&&vis?rq(loop):0}
function run(){if(!raf&&mode&&vis)raf=rq(loop)}
function go(k,say){k=cl(k,0,n-1);tgt=pts[k];
if(rm){mode=0;x=tgt;draw()}else{mode=2;run()}
if(say)L.textContent="Slide "+(k+1)+" of "+n}
function stop(){clearInterval(idle)}
on(T,"pointerdown",e=>{if(e.button)return;stop();ca(raf);raf=mode=moved=0;d={p:e.clientX,s:x,id:e.pointerId};h=[[e.timeStamp,x]]});
on(T,"pointermove",e=>{if(!d)return;var m=d.s+e.clientX-d.p,t=e.timeStamp;
if(!moved&&A(m-d.s)>6){moved=1;T.setPointerCapture(d.id)}
if(!moved)return;
x=m>hi?hi+(m-hi)*.35:m<lo?lo+(m-lo)*.35:m;
h.push([t,x]);while(h.length>2&&t-h[0][0]>100)h.shift();
if(!fr)fr=rq(()=>{fr=0;draw()})});
function up(e){if(!d)return;d=0;if(!moved)return;
var a=h[0],b=h[h.length-1],t=b[0]-a[0];
/* release speed from the last 100 ms of moves */
v=t>0&&e.timeStamp-b[0]<80?(b[1]-a[1])/t*16.7:0;
if(rm)go(near(x));else{mode=1;run()}}
on(T,"pointerup",up);on(T,"pointercancel",up);
on(T,"click",e=>{if(moved){e.preventDefault();e.stopPropagation();moved=0}},1);
on(P,"click",()=>{stop();go(i-1,1)});on(N,"click",()=>{stop();go(i+1,1)});
on(R,"keydown",e=>{var k={ArrowLeft:-1,ArrowRight:1}[e.key];if(k){e.preventDefault();stop();go(i+k,1)}});
on(R,"focusin",e=>{stop();V.scrollLeft=0;var s=e.target.closest(".w1quo-slide");if(s)go(S.indexOf(s))});
on(R,"pointerenter",stop);
var io=new IntersectionObserver(en=>{vis=en[0].isIntersecting;if(vis)run();else{ca(raf);raf=0}});
on(window,"resize",ms);io.observe(R);ms();
/* idle demo: one sleeve every IDLE ms until the pointer arrives or anything is pressed */
if(!rm)idle=setInterval(()=>vis&&!document.hidden&&go(i<n-1?i+1:0),IDLE);
return()=>{ac.abort();io.disconnect();stop();ca(raf);ca(fr)}}
var R=document.querySelector(".w1quo");if(R)init(R);
})();
</script>

With reduced motion: One quote shows at a time and the buttons, keys and drag release swap straight to the next quote without fading.

Running cost: Per frame it writes one track transform plus an opacity and transform for each of the four quotes, and only while moving.

  • Raise `FADE` so a quote vanishes sooner as it slides away, or lower it to keep two quotes visible mid-drag.
  • Set the quote size with `--w1quo-size` and the mark and initials colour with `--w1quo-accent`.
  • Edit the four `figure` blocks to change the words, names and the item each person brought in.

Two Linked Drag Rails Moving at Different Speeds

A walking tour company's photo cards on one rail and the city names in large italic type on a second rail beneath. Both are tied to one position, so dragging either moves the pair, with the names travelling at a slower pace than the photos and still arriving in step on each card. Suits a travel, events or venue list where a second layer of type adds depth.

<section class="w2rai" role="region" aria-roledescription="carousel" aria-label="Lantern Walks tours">
  <div class="w2rai-wrap">
    <div class="w2rai-head">
      <div>
        <p class="w2rai-kicker">Lantern Walks</p>
        <h2 class="w2rai-title">Evening walking tours by the water</h2>
      </div>
      <div class="w2rai-btns">
        <button class="w2rai-btn" type="button" data-d="-1" aria-label="Previous tour" disabled><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M15 5l-7 7 7 7" fill="none" stroke="currentColor" stroke-width="2"/></svg></button>
        <button class="w2rai-btn" type="button" data-d="1" aria-label="Next tour"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M9 5l7 7-7 7" fill="none" stroke="currentColor" stroke-width="2"/></svg></button>
      </div>
    </div>
    <div class="w2rai-view">
      <ol class="w2rai-rail w2rai-a">
        <li class="w2rai-card" role="group" aria-roledescription="slide" aria-label="1 of 5"><img src="https://images.pexels.com/photos/33944600/pexels-photo-33944600.jpeg?auto=compress&cs=tinysrgb&w=800" alt="A red tram on a street of old buildings in downtown Lisbon" draggable="false"><div class="w2rai-meta"><h3>Baixa after dark</h3><p>2 hours, from Praça da Figueira</p><a href="#">Tour details</a></div></li>
        <li class="w2rai-card" role="group" aria-roledescription="slide" aria-label="2 of 5"><img src="https://images.pexels.com/photos/16180699/pexels-photo-16180699.jpeg?auto=compress&cs=tinysrgb&w=800" alt="Porto rooftops and riverside buildings along the Douro at sunset" draggable="false"><div class="w2rai-meta"><h3>Douro at dusk</h3><p>90 minutes, Ribeira to the bridge</p><a href="#">Tour details</a></div></li>
        <li class="w2rai-card" role="group" aria-roledescription="slide" aria-label="3 of 5"><img src="https://images.pexels.com/photos/34065721/pexels-photo-34065721.jpeg?auto=compress&cs=tinysrgb&w=800" alt="Colourful fishing boats moored in Marsaxlokk harbour" draggable="false"><div class="w2rai-meta"><h3>Fishing boats</h3><p>1 hour, along the harbour wall</p><a href="#">Tour details</a></div></li>
        <li class="w2rai-card" role="group" aria-roledescription="slide" aria-label="4 of 5"><img src="https://images.pexels.com/photos/36901145/pexels-photo-36901145.jpeg?auto=compress&cs=tinysrgb&w=800" alt="Birgu marina with a classic boat and limestone buildings across the water" draggable="false"><div class="w2rai-meta"><h3>Marina and bastions</h3><p>2 hours, ferry included</p><a href="#">Tour details</a></div></li>
        <li class="w2rai-card" role="group" aria-roledescription="slide" aria-label="5 of 5"><img src="https://images.pexels.com/photos/20358173/pexels-photo-20358173.jpeg?auto=compress&cs=tinysrgb&w=800" alt="A quiet narrow street in Barcelona with a parked scooter and old stone buildings" draggable="false"><div class="w2rai-meta"><h3>Side streets</h3><p>2 hours, small groups of eight</p><a href="#">Tour details</a></div></li>
      </ol>
    </div>
    <div class="w2rai-view w2rai-names" aria-hidden="true">
      <ol class="w2rai-rail w2rai-b"><li>Lisbon</li><li>Porto</li><li>Marsaxlokk</li><li>Birgu</li><li>Barcelona</li></ol>
    </div>
    <p class="w2rai-live" aria-live="polite"></p>
  </div>
</section>
<style>
  /* Change these: navy background, text, amber accent, card width and city name width (the ratio sets the speed difference). */
  .w2rai { --w2rai-bg: #13203a; --w2rai-ink: #eef1f6; --w2rai-acc: #e8b85c; --w2rai-card: 360px; --w2rai-name: 280px; }
  .w2rai { background: var(--w2rai-bg); color: var(--w2rai-ink); padding: 52px 0 40px; font-family: ui-sans-serif, system-ui, sans-serif; overflow: hidden; }
  .w2rai-wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
  .w2rai-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
  .w2rai-kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .24em; text-transform: uppercase; color: var(--w2rai-acc); }
  .w2rai-title { margin: 10px 0 0; font-size: clamp(26px, 3.6vw, 40px); font-weight: 650; line-height: 1.15; letter-spacing: -.02em; }
  .w2rai-btns { display: flex; gap: 10px; }
  .w2rai-btn { width: 48px; height: 48px; border-radius: 50%; border: 1px solid rgba(238, 241, 246, .35); background: transparent; color: var(--w2rai-ink); display: grid; place-items: center; cursor: pointer; }
  .w2rai-btn:hover { background: rgba(238, 241, 246, .1); }
  .w2rai-btn:disabled { opacity: .3; cursor: default; }
  .w2rai-view { touch-action: pan-y; cursor: grab; user-select: none; }
  .w2rai-rail { display: flex; margin: 0; padding: 0; list-style: none; will-change: transform; }
  .w2rai-card { flex: 0 0 var(--w2rai-card); max-width: 82vw; padding-right: 20px; box-sizing: border-box; transition: opacity .35s; opacity: .55; }
  .w2rai-card.w2rai-on { opacity: 1; }
  .w2rai-card img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 10px; pointer-events: none; }
  .w2rai-meta { position: relative; padding-top: 14px; }
  .w2rai-meta h3 { margin: 0; font-size: 18px; font-weight: 650; }
  .w2rai-meta p { margin: 4px 0 0; font-size: 14px; color: #b9c2d3; }
  .w2rai-meta a { display: inline-flex; align-items: center; min-height: 40px; margin-top: 6px; color: var(--w2rai-acc); font-size: 14px; font-weight: 600; text-decoration: none; }
  .w2rai-meta a:hover { text-decoration: underline; }
  .w2rai-btn:focus-visible, .w2rai-meta a:focus-visible { outline: 2px solid var(--w2rai-acc); outline-offset: 3px; }
  .w2rai-names { margin-top: 18px; padding-top: 14px; border-top: 1px solid rgba(238, 241, 246, .14); }
  .w2rai-b li { flex: 0 0 var(--w2rai-name); font: italic 500 clamp(30px, 4vw, 44px)/1.1 Georgia, "Times New Roman", serif; color: rgba(238, 241, 246, .28); white-space: nowrap; transition: color .35s; }
  .w2rai-b li.w2rai-on { color: var(--w2rai-ink); }
  .w2rai-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  @media (prefers-reduced-motion: reduce) { .w2rai-card, .w2rai-b li { transition: none; } }
</style>
<script>
(function(){
/* Change these: friction per frame, rubber band past the ends, idle advance in ms. */
var FRICTION=.93,RUBBER=.3,IDLE=3000;
var R=document.querySelector(".w2rai"),Q=function(s){return R.querySelectorAll(s)},M=Math,F=requestAnimationFrame;
var A=Q(".w2rai-a")[0],B=Q(".w2rai-b")[0],cs=Q(".w2rai-card"),nm=Q(".w2rai-b li"),vw=Q(".w2rai-view"),bt=Q(".w2rai-btn"),lv=Q(".w2rai-live")[0];
var n=cs.length,rm=matchMedia("(prefers-reduced-motion: reduce)").matches,x=0,v=0,tx=0,raf=0,dn=0,sx,x0,H,mv,f,I=-1,V=1,au=0;
function cl(i){return M.max(0,M.min(n-1,i))}
function show(i){if(i==I)return;cs.forEach(function(e,k){e.classList.toggle("w2rai-on",k==i);nm[k].classList.toggle("w2rai-on",k==i)});I=i;bt[0].disabled=!i;bt[1].disabled=i==n-1}
/* x drives the photo rail; the names rail moves by the ratio of the two widths, so it travels slower but lands in step */
function loop(){raf=0;var s=cs[0].offsetWidth,m=-(n-1)*s,g,p;
if(!dn){if(tx==null){x+=v;v*=FRICTION;if(x>0||x<m)v*=.6;if(M.abs(v)<.5)tx=cl(M.round(-x/s))}
if(tx!=null){g=-tx*s;x=rm?g:x+(g-x)*.15;if(M.abs(g-x)<.5)x=g}}
p=x>0?x*RUBBER:x<m?m+(x-m)*RUBBER:x;A.style.transform="translate3d("+p+"px,0,0)";B.style.transform="translate3d("+p*nm[0].offsetWidth/s+"px,0,0)";show(cl(M.round(-p/s)));
if(V&&(dn||tx==null||x!=-tx*s))raf=F(loop)}
function k(){raf=raf||F(loop)}
function go(i,say){tx=cl(i);v=0;k();if(say)lv.textContent="Tour "+(tx+1)+" of "+n+": "+cs[tx].querySelector("h3").textContent}
function S(){clearTimeout(au);au=-1}
function up(e){if(!dn)return;dn=0;if(rm||e.timeStamp-H>100)v=0;tx=null;k()}
vw.forEach(function(el,j){
el.onpointerdown=function(e){S();dn=1;mv=0;sx=e.clientX;x0=x;v=0;f=j?cs[0].offsetWidth/nm[0].offsetWidth:1;k()};
el.onpointermove=function(e){if(!dn)return;var d=(e.clientX-sx)*f;if(M.abs(d)>6&&!mv){mv=1;el.setPointerCapture(e.pointerId)}v=v*.5+(x0+d-x)*.5;x=x0+d;H=e.timeStamp;k()};
el.onpointerup=el.onpointercancel=up;
el.addEventListener("click",function(e){if(mv){e.preventDefault();e.stopPropagation()}},true)});
/* tabbing to a link in a card brings that card into place */
cs.forEach(function(c,i){c.addEventListener("focusin",function(){R.scrollLeft=0;go(i)})});
bt.forEach(function(b){b.onclick=function(){S();go(I+ +b.dataset.d,1)}});
R.onkeydown=function(e){var i={ArrowLeft:I-1,ArrowRight:I+1}[e.key];if(i!=null){e.preventDefault();S();go(i,1)}};
R.onpointerenter=S;R.addEventListener("focusin",S);
function tick(){if(au<0)return;if(V)go((I+1)%n);au=setTimeout(tick,IDLE)}
new IntersectionObserver(function(e){V=e[0].isIntersecting;V&&k()}).observe(R);
k();
function W(){au=setTimeout(tick,2200)}rm||(document.readyState=="complete"?W():addEventListener("load",W));
})();
</script>

With reduced motion: Both rails jump together to the chosen tour, and a drag follows the pointer with no coast afterwards.

Running cost: Two transforms per frame from one shared position, written only while dragging or settling.

  • The speed difference comes from the width ratio of `--w2rai-card` and `--w2rai-name`; make the names narrower for a slower lower rail.
  • Change `FRICTION` to lengthen or shorten the coast after a flick, and `RUBBER` for the pull at the ends.
  • Recolour the night navy and amber with `--w2rai-bg` and `--w2rai-acc`.

Vertical Drag Menu Slider Inside a Phone Mockup

A coffee bar's menu shown inside a drawn phone, one drink filling the screen at a time. Drag up or down on the screen and it follows your finger; a quick flick coasts past a drink or two before it eases onto the nearest one, and it stretches a little at the first and last. Good for previewing an app screen or a mobile-first menu on a desktop page.

<section class="w2pho" role="region" aria-roledescription="carousel" aria-label="Marrow Coffee menu">
  <div class="w2pho-wrap">
    <div class="w2pho-copy">
      <p class="w2pho-kicker">Marrow Coffee, Leith Walk</p>
      <h2 class="w2pho-title">The bar menu, one drink per screen</h2>
      <p class="w2pho-text">Swipe up and down inside the phone, or use the buttons and arrow keys. A quick flick carries on for a drink or two before it settles.</p>
      <div class="w2pho-btns">
        <button class="w2pho-btn" type="button" data-d="-1" aria-label="Previous drink" disabled><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M5 15l7-7 7 7" fill="none" stroke="currentColor" stroke-width="2"/></svg></button>
        <button class="w2pho-btn" type="button" data-d="1" aria-label="Next drink"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true"><path d="M5 9l7 7 7-7" fill="none" stroke="currentColor" stroke-width="2"/></svg></button>
      </div>
    </div>
    <div class="w2pho-phone">
      <div class="w2pho-screen" tabindex="0">
        <ol class="w2pho-track">
          <li class="w2pho-slide" role="group" aria-roledescription="slide" aria-label="1 of 5"><img src="https://images.pexels.com/photos/4921556/pexels-photo-4921556.jpeg?auto=compress&cs=tinysrgb&w=700" alt="Hands holding a small ceramic cup of espresso, seen from above" draggable="false"><div class="w2pho-info"><h3>Espresso</h3><p>Double shot, house blend with notes of cocoa and plum.</p><span>3.20</span></div></li>
          <li class="w2pho-slide" role="group" aria-roledescription="slide" aria-label="2 of 5"><img src="https://images.pexels.com/photos/29507967/pexels-photo-29507967.jpeg?auto=compress&cs=tinysrgb&w=700" alt="Pour-over coffee through a cloth filter beside a cup on a wooden table" draggable="false"><div class="w2pho-info"><h3>Pour-over</h3><p>Single origin through a cloth filter, brewed to order.</p><span>4.60</span></div></li>
          <li class="w2pho-slide" role="group" aria-roledescription="slide" aria-label="3 of 5"><img src="https://images.pexels.com/photos/459489/pexels-photo-459489.jpeg?auto=compress&cs=tinysrgb&w=700" alt="Latte with heart latte art in a pale blue cup and saucer" draggable="false"><div class="w2pho-info"><h3>Latte</h3><p>Whole or oat milk, poured with a heart.</p><span>3.90</span></div></li>
          <li class="w2pho-slide" role="group" aria-roledescription="slide" aria-label="4 of 5"><img src="https://images.pexels.com/photos/39218055/pexels-photo-39218055.jpeg?auto=compress&cs=tinysrgb&w=700" alt="Glass of iced coffee with a straw on a sunlit table" draggable="false"><div class="w2pho-info"><h3>Iced coffee</h3><p>Slow steeped overnight, served over ice.</p><span>4.10</span></div></li>
          <li class="w2pho-slide" role="group" aria-roledescription="slide" aria-label="5 of 5"><img src="https://images.pexels.com/photos/997670/pexels-photo-997670.jpeg?auto=compress&cs=tinysrgb&w=700" alt="Cappuccino with latte art in a black mug" draggable="false"><div class="w2pho-info"><h3>Cappuccino</h3><p>Equal thirds, dusted with cocoa if you ask.</p><span>3.70</span></div></li>
        </ol>
        <div class="w2pho-dots" aria-hidden="true"><i class="w2pho-on"></i><i></i><i></i><i></i><i></i></div>
      </div>
    </div>
    <p class="w2pho-live" aria-live="polite"></p>
  </div>
</section>
<style>
  /* Change these: graphite background, cream text, copper accent, phone size. */
  .w2pho { --w2pho-bg: #26282c; --w2pho-ink: #f1ece4; --w2pho-acc: #d79a6a; --w2pho-w: 290px; --w2pho-h: 590px; }
  .w2pho { background: var(--w2pho-bg); color: var(--w2pho-ink); padding: 56px 16px; font-family: ui-sans-serif, system-ui, sans-serif; overflow: hidden; }
  .w2pho-wrap { max-width: 940px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 40px; align-items: center; }
  @media (min-width: 768px) { .w2pho-wrap { grid-template-columns: minmax(0, 1fr) auto; gap: 64px; } }
  .w2pho-kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .24em; text-transform: uppercase; color: var(--w2pho-acc); }
  .w2pho-title { margin: 12px 0 0; font-size: clamp(28px, 4vw, 42px); font-weight: 650; line-height: 1.12; letter-spacing: -.02em; }
  .w2pho-text { margin: 16px 0 0; max-width: 26rem; font-size: 16px; line-height: 1.65; color: #c3bdb3; }
  .w2pho-btns { display: flex; gap: 10px; margin-top: 28px; }
  .w2pho-btn { width: 48px; height: 48px; border-radius: 14px; border: 1px solid rgba(241, 236, 228, .3); background: transparent; color: var(--w2pho-ink); display: grid; place-items: center; cursor: pointer; }
  .w2pho-btn:hover { background: rgba(241, 236, 228, .08); }
  .w2pho-btn:disabled { opacity: .3; cursor: default; }
  .w2pho-phone { justify-self: center; width: var(--w2pho-w); height: var(--w2pho-h); padding: 12px; border-radius: 46px; background: #0e0f11; box-shadow: 0 0 0 2px #3a3d42, 0 40px 80px -30px rgba(0, 0, 0, .8); box-sizing: border-box; }
  .w2pho-screen { position: relative; width: 100%; height: 100%; border-radius: 34px; overflow: hidden; background: #f6f1ea; touch-action: pan-x; cursor: grab; user-select: none; }
  .w2pho-screen:focus-visible, .w2pho-btn:focus-visible { outline: 2px solid var(--w2pho-acc); outline-offset: 4px; }
  .w2pho-track { margin: 0; padding: 0; list-style: none; height: 100%; will-change: transform; }
  .w2pho-slide { position: relative; height: 100%; color: #26282c; }
  .w2pho-slide img { display: block; width: 100%; height: 70%; object-fit: cover; pointer-events: none; }
  .w2pho-info { padding: 20px 22px; }
  .w2pho-info h3 { margin: 0; font-size: 24px; font-weight: 650; letter-spacing: -.01em; }
  .w2pho-info p { margin: 6px 0 0; font-size: 14px; line-height: 1.5; color: #55514b; }
  .w2pho-info span { position: absolute; right: 22px; top: calc(70% + 22px); font-size: 16px; font-weight: 700; color: #8a4f26; }
  .w2pho-dots { position: absolute; right: 10px; top: 50%; display: grid; gap: 6px; transform: translateY(-50%); }
  .w2pho-dots i { width: 6px; height: 6px; border-radius: 50%; background: rgba(255, 255, 255, .55); box-shadow: 0 0 0 1px rgba(0, 0, 0, .15); transition: transform .3s; }
  .w2pho-dots i.w2pho-on { background: #fff; transform: scale(1.5); }
  .w2pho-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  @media (max-width: 380px) { .w2pho { --w2pho-w: 270px; --w2pho-h: 550px; } }
  @media (prefers-reduced-motion: reduce) { .w2pho-dots i { transition: none; } }
</style>
<script>
(function(){
/* Change these: friction per frame, rubber band past the ends, idle advance in ms. */
var FRICTION=.94,RUBBER=.3,IDLE=3000;
var R=document.querySelector(".w2pho"),Q=function(s){return R.querySelectorAll(s)},M=Math,F=requestAnimationFrame;
var sc=Q(".w2pho-screen")[0],tr=Q(".w2pho-track")[0],it=Q(".w2pho-slide"),dt=Q(".w2pho-dots i"),bt=Q(".w2pho-btn"),lv=Q(".w2pho-live")[0];
var n=it.length,rm=matchMedia("(prefers-reduced-motion: reduce)").matches,y=0,v=0,ty=0,raf=0,dn=0,sy,y0,H,I=0,V=1,au=0;
function cl(i){return M.max(0,M.min(n-1,i))}
function show(i){if(i==I)return;dt[I].classList.remove("w2pho-on");dt[i].classList.add("w2pho-on");I=i;bt[0].disabled=!i;bt[1].disabled=i==n-1;
it.forEach(function(e,k){e.ariaHidden=k!=i})}
/* vertical track: drag, coast with friction, then ease onto the nearest drink */
function loop(){raf=0;var s=sc.offsetHeight,m=-(n-1)*s,g,p;
if(!dn){if(ty==null){y+=v;v*=FRICTION;if(y>0||y<m)v*=.6;if(M.abs(v)<.5)ty=cl(M.round(-y/s))}
if(ty!=null){g=-ty*s;y=rm?g:y+(g-y)*.15;if(M.abs(g-y)<.5)y=g}}
p=y>0?y*RUBBER:y<m?m+(y-m)*RUBBER:y;tr.style.transform="translate3d(0,"+p+"px,0)";show(cl(M.round(-p/s)));
if(V&&(dn||ty==null||y!=-ty*s))raf=F(loop)}
function k(){raf=raf||F(loop)}
function go(i,say){ty=cl(i);v=0;k();if(say)lv.textContent="Drink "+(ty+1)+" of "+n+": "+it[ty].querySelector("h3").textContent}
function S(){clearTimeout(au);au=-1}
function up(e){if(!dn)return;dn=0;if(rm||e.timeStamp-H>100)v=0;ty=null;k()}
sc.onpointerdown=function(e){S();dn=1;sy=e.clientY;y0=y;v=0;sc.setPointerCapture(e.pointerId);k()};
sc.onpointermove=function(e){if(!dn)return;var d=e.clientY-sy;v=v*.5+(y0+d-y)*.5;y=y0+d;H=e.timeStamp;k()};
sc.onpointerup=sc.onpointercancel=up;
bt.forEach(function(b){b.onclick=function(){S();go(I+ +b.dataset.d,1)}});
R.onkeydown=function(e){var i={ArrowUp:I-1,ArrowLeft:I-1,ArrowDown:I+1,ArrowRight:I+1,Home:0,End:n-1}[e.key];if(i!=null){e.preventDefault();S();go(i,1)}};
R.onpointerenter=S;R.addEventListener("focusin",S);
function tick(){if(au<0)return;if(V)go((I+1)%n);au=setTimeout(tick,IDLE)}
new IntersectionObserver(function(e){V=e[0].isIntersecting;V&&k()}).observe(R);
it.forEach(function(e,k){e.ariaHidden=k>0});
function A(){au=setTimeout(tick,2200)}rm||(document.readyState=="complete"?A():addEventListener("load",A));
})();
</script>

With reduced motion: Each swipe, button or key lands straight on the next drink with no coasting and no ease.

Running cost: One transform on the screen's track per frame, only while a finger is down or the screen is settling.

  • Change `FRICTION` for a longer or shorter coast, and `RUBBER` for how much the screen stretches past the ends.
  • Resize the handset with `--w2pho-w` and `--w2pho-h`; each slide takes the full screen height so the snap follows automatically.
  • Swap the graphite and copper colours through `--w2pho-bg` and `--w2pho-acc`.

Performance notes

The track moves with one translate3d on a single layer, so dragging never triggers layout. During a drag the script only records the pointer position; it writes the transform once per frame. After release the friction loop runs for well under a second and stops itself when the speed falls below a small threshold.

Image transitions between slides draw only while a change is happening. The canvas version paints tiles of the outgoing and incoming photos for the few hundred milliseconds of the change and then leaves a plain image in place; the CSS version moves pre-cut strips with transform. All sliders stop their idle advance when scrolled out of view or when the tab is hidden.

Questions

How do I make a draggable slider in plain JavaScript?

Listen for pointerdown on the track, call setPointerCapture so moves keep arriving even off the element, and translate the track by the distance moved. On pointerup, measure the recent speed, keep moving while multiplying the speed by a friction value each frame, then ease to the nearest slide.

How do I stop a drag from opening a slide's link?

Track how far the pointer travelled. If it moved more than a few pixels between pointerdown and pointerup, cancel the click that follows with preventDefault in a capturing click listener. A short tap still opens the link as normal.

Why does my slider block page scrolling on phones?

The track is probably cancelling every touch. Set touch-action: pan-y on it so the browser keeps vertical scrolling for itself and only hands sideways movement to your script. MDN lists touch-action in all current browsers.

Is a carousel accessible to keyboard and screen reader users?

It can be. Give the root a label and a carousel role description, mark each slide as a group labelled with its position, provide real previous and next buttons, support the arrow keys, and stop any automatic advance as soon as someone interacts or asks for reduced motion.

Should a carousel slide on its own?

Mostly no. Automatic movement pulls the eye and can move content away while someone reads. The sliders here advance gently only as a preview until the first touch, click or key press, and never when reduced motion is on.

Also in the gallery: React Image Carousel with Scroll Snap, Autoplay, Dots, Thumbnails and Swipe, Snap Scroll Bread Shelf with Arrow Buttons, Slide Projector Photo Carousel with a Ribbed Tray That Clicks Round and Drops Each Frame into the Beam.

More collections: Horizontal Scroll Sections, Expanding Cards and Image Panels, Image Reveal on Hover. All galleries and carousels. Build your site free to have a full site built around them.

Product

Who It's For

Features

Resources

Company

View Sitemap