StealThis .dev
Patterns Medium

Scroll Velocity Text

Horizontal scrolling text marquee that speeds up or slows down based on the user's scroll velocity.

Open in Lab
css javascript vue svelte
Targets: TS JS HTML React Vue Svelte

Code

Scroll Velocity Text

A horizontal scrolling text marquee that dynamically adjusts its speed based on how fast the user scrolls. Faster scrolling makes the text move faster; slow or no scrolling returns it to a gentle base speed.

How it works

  1. A duplicated text strip is animated with CSS translateX to create a seamless loop
  2. JavaScript tracks scroll delta between frames to measure velocity
  3. The velocity is smoothed with linear interpolation and mapped to the animation speed
  4. The direction can reverse based on scroll direction (up vs. down)

Customization

  • Set baseSpeed to control the idle animation speed
  • Adjust the speedMultiplier for how much scroll affects the marquee
  • Use --marquee-gap to control spacing between repeated text
  • Change direction with the direction prop/attribute

When to use it

  • Hero sections with bold typography
  • Section dividers with scrolling labels
  • Decorative background text bands
  • Interactive portfolio page elements