# Rotating word drum

> A sentence that ends in a metal roller: scroll or use the arrow keys and the words turn like a combination lock.

- Category: [Text & scroll](https://library.aimran.es/components/text-scroll)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-tx-drum-picker
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

This headline finishes on a brushed metal drum, like the wheels of a combination lock. The words sit in a scroll snap container, and a few lines of JavaScript tilt each one in 3D depending on how far it is from the center window. It is a tactile way to show who a product is for on landing pages, agencies or booking tools.

Change the start of the sentence in the text field and the words in the list. The main color frames the window and the chosen word, the secondary one colors the rest. It behaves as a listbox: arrow keys, Home and End move it, and the choice is announced.

## Code

### HTML

```html
<div class="uvq14-drm"><p class="lb" id="uvq14-drm-l">Websites for</p><div class="dr"><div class="sc" tabindex="0" role="listbox" aria-labelledby="uvq14-drm-l"><div role="option" id="uvq14-drm-0" aria-selected="false">restaurants</div><div role="option" id="uvq14-drm-1" aria-selected="true">studios</div><div role="option" id="uvq14-drm-2" aria-selected="false">shops</div><div role="option" id="uvq14-drm-3" aria-selected="false">clinics</div><div role="option" id="uvq14-drm-4" aria-selected="false">bands</div><div role="option" id="uvq14-drm-5" aria-selected="false">weddings</div></div><i class="wn" aria-hidden="true"></i></div></div>
```

### CSS

```css
.uvq14-drm {
  --c1: #4f46e5;
  --c2: #0f172a;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uvq14-drm {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  width: 21em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4em;
  font-size: calc(var(--s) * 1.45);
  --h: 1.7em;
}

.uvq14-drm .lb {
  margin: 0;
  font-weight: 800;
  letter-spacing: -.02em;
  white-space: nowrap;
}

.uvq14-drm .dr {
  position: relative;
  width: 7.6em;
  height: calc(var(--h) * 3);
  border-radius: .45em;
  background: linear-gradient(#5b6170,#c9ccd3 18%,#f4f5f7 42%,#fff 50%,#f4f5f7 58%,#c9ccd3 82%,#5b6170);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.25),inset .25em 0 .3em -.2em rgba(0,0,0,.3),inset -.25em 0 .3em -.2em rgba(0,0,0,.3),0 .8em 1.4em -.8em rgba(0,0,0,.5);
}

.uvq14-drm .sc {
  position: relative;
  height: 100%;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  outline: 0;
  box-sizing: border-box;
  padding: var(--h) 0;
  border-radius: inherit;
  cursor: ns-resize;
}

.uvq14-drm .sc::-webkit-scrollbar {
  display: none;
}

.uvq14-drm .sc:focus-visible {
  box-shadow: 0 0 0 2px var(--c1);
}

.uvq14-drm [role=option] {
  height: var(--h);
  line-height: var(--h);
  text-align: center;
  font-weight: 800;
  letter-spacing: -.02em;
  color: var(--c2);
  scroll-snap-align: center;
  transform: perspective(9em) rotateX(calc(var(--d,0) * -32deg)) scale(calc(1 - var(--a,0) * .12));
  opacity: calc(1 - var(--a,0) * .55);
  cursor: pointer;
  user-select: none;
}

.uvq14-drm [aria-selected=true] {
  color: var(--c1);
}

.uvq14-drm .wn {
  position: absolute;
  left: -.2em;
  right: -.2em;
  top: var(--h);
  height: var(--h);
  border-block: 2px solid var(--c1);
  border-radius: .15em;
  pointer-events: none;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,0);
}

.uvq14-drm .wn::before,.uvq14-drm .wn::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 0;
  height: 0;
  border: .28em solid transparent;
  margin-top: -.28em;
}

.uvq14-drm .wn::before {
  left: -.3em;
  border-left-color: var(--c1);
}

.uvq14-drm .wn::after {
  right: -.3em;
  border-right-color: var(--c1);
}
```

### JavaScript

```js
document.querySelectorAll(".uvq14-drm").forEach(el => {
  const sc=el.querySelector(".sc"),os=[...sc.children];const rm=matchMedia("(prefers-reduced-motion: reduce)").matches;let cur=-1,raf=0;
const u=()=>{raf=0;const r=sc.getBoundingClientRect(),c=r.top+r.height/2;let best=0,bd=1e9;os.forEach((o,i)=>{const q=o.getBoundingClientRect(),d=(q.top+q.height/2-c)/q.height;o.style.setProperty("--d",Math.max(-2.5,Math.min(2.5,d)).toFixed(3));o.style.setProperty("--a",Math.min(2,Math.abs(d)).toFixed(3));if(Math.abs(d)<bd){bd=Math.abs(d);best=i}});if(best!==cur){cur=best;os.forEach((o,i)=>o.setAttribute("aria-selected",String(i===cur)));sc.setAttribute("aria-activedescendant",os[cur].id)}};
const to=(i,b)=>{i=Math.max(0,Math.min(os.length-1,i));sc.scrollTo({top:os[i].offsetTop-(sc.clientHeight-os[i].offsetHeight)/2,behavior:b||(rm?"auto":"smooth")})};
sc.addEventListener("scroll",()=>{if(!raf)raf=requestAnimationFrame(u)},{passive:true});
sc.addEventListener("keydown",e=>{const m={ArrowDown:1,ArrowUp:-1}[e.key];if(m){e.preventDefault();to(cur+m)}if(e.key==="Home"){e.preventDefault();to(0)}if(e.key==="End"){e.preventDefault();to(os.length-1)}});
os.forEach((o,i)=>o.addEventListener("click",()=>to(i)));
const ro=new ResizeObserver(()=>u());ro.observe(sc);to(1,"auto");u();
return()=>{ro.disconnect();cancelAnimationFrame(raf)}
});
```

### React

```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uvq14-drm {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  width: 21em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4em;
  font-size: calc(var(--s) * 1.45);
  --h: 1.7em;
}

.uvq14-drm .lb {
  margin: 0;
  font-weight: 800;
  letter-spacing: -.02em;
  white-space: nowrap;
}

.uvq14-drm .dr {
  position: relative;
  width: 7.6em;
  height: calc(var(--h) * 3);
  border-radius: .45em;
  background: linear-gradient(#5b6170,#c9ccd3 18%,#f4f5f7 42%,#fff 50%,#f4f5f7 58%,#c9ccd3 82%,#5b6170);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.25),inset .25em 0 .3em -.2em rgba(0,0,0,.3),inset -.25em 0 .3em -.2em rgba(0,0,0,.3),0 .8em 1.4em -.8em rgba(0,0,0,.5);
}

.uvq14-drm .sc {
  position: relative;
  height: 100%;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  outline: 0;
  box-sizing: border-box;
  padding: var(--h) 0;
  border-radius: inherit;
  cursor: ns-resize;
}

.uvq14-drm .sc::-webkit-scrollbar {
  display: none;
}

.uvq14-drm .sc:focus-visible {
  box-shadow: 0 0 0 2px var(--c1);
}

.uvq14-drm [role=option] {
  height: var(--h);
  line-height: var(--h);
  text-align: center;
  font-weight: 800;
  letter-spacing: -.02em;
  color: var(--c2);
  scroll-snap-align: center;
  transform: perspective(9em) rotateX(calc(var(--d,0) * -32deg)) scale(calc(1 - var(--a,0) * .12));
  opacity: calc(1 - var(--a,0) * .55);
  cursor: pointer;
  user-select: none;
}

.uvq14-drm [aria-selected=true] {
  color: var(--c1);
}

.uvq14-drm .wn {
  position: absolute;
  left: -.2em;
  right: -.2em;
  top: var(--h);
  height: var(--h);
  border-block: 2px solid var(--c1);
  border-radius: .15em;
  pointer-events: none;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,0);
}

.uvq14-drm .wn::before,.uvq14-drm .wn::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 0;
  height: 0;
  border: .28em solid transparent;
  margin-top: -.28em;
}

.uvq14-drm .wn::before {
  left: -.3em;
  border-left-color: var(--c1);
}

.uvq14-drm .wn::after {
  right: -.3em;
  border-right-color: var(--c1);
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  const sc=el.querySelector(".sc"),os=[...sc.children];const rm=matchMedia("(prefers-reduced-motion: reduce)").matches;let cur=-1,raf=0;
const u=()=>{raf=0;const r=sc.getBoundingClientRect(),c=r.top+r.height/2;let best=0,bd=1e9;os.forEach((o,i)=>{const q=o.getBoundingClientRect(),d=(q.top+q.height/2-c)/q.height;o.style.setProperty("--d",Math.max(-2.5,Math.min(2.5,d)).toFixed(3));o.style.setProperty("--a",Math.min(2,Math.abs(d)).toFixed(3));if(Math.abs(d)<bd){bd=Math.abs(d);best=i}});if(best!==cur){cur=best;os.forEach((o,i)=>o.setAttribute("aria-selected",String(i===cur)));sc.setAttribute("aria-activedescendant",os[cur].id)}};
const to=(i,b)=>{i=Math.max(0,Math.min(os.length-1,i));sc.scrollTo({top:os[i].offsetTop-(sc.clientHeight-os[i].offsetHeight)/2,behavior:b||(rm?"auto":"smooth")})};
sc.addEventListener("scroll",()=>{if(!raf)raf=requestAnimationFrame(u)},{passive:true});
sc.addEventListener("keydown",e=>{const m={ArrowDown:1,ArrowUp:-1}[e.key];if(m){e.preventDefault();to(cur+m)}if(e.key==="Home"){e.preventDefault();to(0)}if(e.key==="End"){e.preventDefault();to(os.length-1)}});
os.forEach((o,i)=>o.addEventListener("click",()=>to(i)));
const ro=new ResizeObserver(()=>u());ro.observe(sc);to(1,"auto");u();
return()=>{ro.disconnect();cancelAnimationFrame(raf)}
}

export default function TxDrumPicker() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#4f46e5",
          "--c2": "#0f172a",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq14-drm"><p className="lb" id="uvq14-drm-l">Websites for</p><div className="dr"><div className="sc" tabIndex={0} role="listbox" aria-labelledby="uvq14-drm-l"><div role="option" id="uvq14-drm-0" aria-selected="false">restaurants</div><div role="option" id="uvq14-drm-1" aria-selected="true">studios</div><div role="option" id="uvq14-drm-2" aria-selected="false">shops</div><div role="option" id="uvq14-drm-3" aria-selected="false">clinics</div><div role="option" id="uvq14-drm-4" aria-selected="false">bands</div><div role="option" id="uvq14-drm-5" aria-selected="false">weddings</div></div><i className="wn" aria-hidden="true"></i></div></div>
      </div>
    </>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Rotating word drum” block (Text & scroll) from AIMRAN Library to my project.

## What it is
A sentence that ends in a metal roller: scroll or use the arrow keys and the words turn like a combination lock.

## Chosen settings
- Main color: #4f46e5
- Secondary color: #0f172a
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "Webs para"

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with plain HTML and CSS (the reference wraps it in a React component with its CSS). If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uvq14-drm {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  width: 21em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4em;
  font-size: calc(var(--s) * 1.45);
  --h: 1.7em;
}

.uvq14-drm .lb {
  margin: 0;
  font-weight: 800;
  letter-spacing: -.02em;
  white-space: nowrap;
}

.uvq14-drm .dr {
  position: relative;
  width: 7.6em;
  height: calc(var(--h) * 3);
  border-radius: .45em;
  background: linear-gradient(#5b6170,#c9ccd3 18%,#f4f5f7 42%,#fff 50%,#f4f5f7 58%,#c9ccd3 82%,#5b6170);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.25),inset .25em 0 .3em -.2em rgba(0,0,0,.3),inset -.25em 0 .3em -.2em rgba(0,0,0,.3),0 .8em 1.4em -.8em rgba(0,0,0,.5);
}

.uvq14-drm .sc {
  position: relative;
  height: 100%;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  outline: 0;
  box-sizing: border-box;
  padding: var(--h) 0;
  border-radius: inherit;
  cursor: ns-resize;
}

.uvq14-drm .sc::-webkit-scrollbar {
  display: none;
}

.uvq14-drm .sc:focus-visible {
  box-shadow: 0 0 0 2px var(--c1);
}

.uvq14-drm [role=option] {
  height: var(--h);
  line-height: var(--h);
  text-align: center;
  font-weight: 800;
  letter-spacing: -.02em;
  color: var(--c2);
  scroll-snap-align: center;
  transform: perspective(9em) rotateX(calc(var(--d,0) * -32deg)) scale(calc(1 - var(--a,0) * .12));
  opacity: calc(1 - var(--a,0) * .55);
  cursor: pointer;
  user-select: none;
}

.uvq14-drm [aria-selected=true] {
  color: var(--c1);
}

.uvq14-drm .wn {
  position: absolute;
  left: -.2em;
  right: -.2em;
  top: var(--h);
  height: var(--h);
  border-block: 2px solid var(--c1);
  border-radius: .15em;
  pointer-events: none;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,0);
}

.uvq14-drm .wn::before,.uvq14-drm .wn::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 0;
  height: 0;
  border: .28em solid transparent;
  margin-top: -.28em;
}

.uvq14-drm .wn::before {
  left: -.3em;
  border-left-color: var(--c1);
}

.uvq14-drm .wn::after {
  right: -.3em;
  border-right-color: var(--c1);
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  const sc=el.querySelector(".sc"),os=[...sc.children];const rm=matchMedia("(prefers-reduced-motion: reduce)").matches;let cur=-1,raf=0;
const u=()=>{raf=0;const r=sc.getBoundingClientRect(),c=r.top+r.height/2;let best=0,bd=1e9;os.forEach((o,i)=>{const q=o.getBoundingClientRect(),d=(q.top+q.height/2-c)/q.height;o.style.setProperty("--d",Math.max(-2.5,Math.min(2.5,d)).toFixed(3));o.style.setProperty("--a",Math.min(2,Math.abs(d)).toFixed(3));if(Math.abs(d)<bd){bd=Math.abs(d);best=i}});if(best!==cur){cur=best;os.forEach((o,i)=>o.setAttribute("aria-selected",String(i===cur)));sc.setAttribute("aria-activedescendant",os[cur].id)}};
const to=(i,b)=>{i=Math.max(0,Math.min(os.length-1,i));sc.scrollTo({top:os[i].offsetTop-(sc.clientHeight-os[i].offsetHeight)/2,behavior:b||(rm?"auto":"smooth")})};
sc.addEventListener("scroll",()=>{if(!raf)raf=requestAnimationFrame(u)},{passive:true});
sc.addEventListener("keydown",e=>{const m={ArrowDown:1,ArrowUp:-1}[e.key];if(m){e.preventDefault();to(cur+m)}if(e.key==="Home"){e.preventDefault();to(0)}if(e.key==="End"){e.preventDefault();to(os.length-1)}});
os.forEach((o,i)=>o.addEventListener("click",()=>to(i)));
const ro=new ResizeObserver(()=>u());ro.observe(sc);to(1,"auto");u();
return()=>{ro.disconnect();cancelAnimationFrame(raf)}
}

export default function TxDrumPicker() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#4f46e5",
          "--c2": "#0f172a",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq14-drm"><p className="lb" id="uvq14-drm-l">Websites for</p><div className="dr"><div className="sc" tabIndex={0} role="listbox" aria-labelledby="uvq14-drm-l"><div role="option" id="uvq14-drm-0" aria-selected="false">restaurants</div><div role="option" id="uvq14-drm-1" aria-selected="true">studios</div><div role="option" id="uvq14-drm-2" aria-selected="false">shops</div><div role="option" id="uvq14-drm-3" aria-selected="false">clinics</div><div role="option" id="uvq14-drm-4" aria-selected="false">bands</div><div role="option" id="uvq14-drm-5" aria-selected="false">weddings</div></div><i className="wn" aria-hidden="true"></i></div></div>
      </div>
    </>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
