Skip to main content

Velocity Marquee

Continuous horizontal marquee whose travel speed and skewX respond to scroll velocity with spring inertia, automatic direction reversal, and accessible pause controls.

SPRING INERTIA * SCROLL VELOCITY * DYNAMIC SKEW *

Customize

Base speed (px/s)48
Max skew (deg)14

Installation

npx shadcn@latest add @kinetic/velocity-marquee

Usage

Pass a repeated phrase via text or arbitrary inline JSX via children. VelocityMarquee measures the first segment width with ResizeObserver, wraps seamlessly across repeated segments (repeat, default 3, clamped 2 to 6) separated by gapPx (default 32), and accelerates plus tilts (skewX) with scroll velocity through spring inertia.

import { VelocityMarquee } from "@/components/kinetic/ui/velocity-marquee";

interface TickerBandProps {
  readonly phrase: string;
}

export function TickerBand({ phrase }: TickerBandProps) {
  return (
    <VelocityMarquee
      text={phrase}
      baseVelocity={48}
      maxSkewDeg={14}
      className="py-4 text-3xl font-semibold tracking-tight"
    />
  );
}

Scroll coupling, direction reversal, and local scroll containers

Scroll speed feeds a spring (stiffness, default 160; damping, default 22) that adds velocity scaled by velocityFactor (default 0.45) and tilts the track up to maxSkewDeg (default 14, clamped 0 to 45) via skewFactor (default 0.018), decaying smoothly back to baseVelocity (default 48 px/s) once scrolling stops.

When reverseOnScroll is true (default), scrolling down and up flips the marquee direction to follow the scroll gesture. Pass a local scrollContainerRef when the marquee lives inside a scrollable panel instead of scrolling the main window.

"use client";

import { useRef, useState } from "react";
import { VelocityMarquee } from "@/components/kinetic/ui/velocity-marquee";

interface ScrollPanelTickerProps {
  readonly items: readonly string[];
}

export function ScrollPanelTicker({ items }: ScrollPanelTickerProps) {
  const scrollRef = useRef<HTMLDivElement>(null);
  const [paused, setPaused] = useState(false);

  return (
    <div className="space-y-3">
      <button type="button" onClick={() => setPaused((prev) => !prev)}>
        {paused ? "Resume marquee" : "Pause marquee"}
      </button>
      <div ref={scrollRef} className="max-h-64 overflow-y-auto border border-border">
        <div className="py-12">
          <VelocityMarquee
            scrollContainerRef={scrollRef}
            reverseOnScroll={true}
            pauseOnHover={true}
            paused={paused}
            gapPx={40}
            className="text-2xl font-medium"
          >
            <span className="flex items-center gap-10">
              {items.map((item) => (
                <span key={item}>{item}</span>
              ))}
            </span>
          </VelocityMarquee>
        </div>
        <div className="h-64" />
      </div>
    </div>
  );
}

Imperative control

Attach a VelocityMarqueeHandle ref to inject an immediate velocity kick with impulse(velocity) (in px/s, positive or negative, clamped to +/-4000) or clear accumulated offset, velocity, and skew back to rest with reset().

"use client";

import { useRef } from "react";
import {
  VelocityMarquee,
  type VelocityMarqueeHandle,
} from "@/components/kinetic/ui/velocity-marquee";

export function ControlledMarquee() {
  const marqueeRef = useRef<VelocityMarqueeHandle>(null);

  return (
    <div className="space-y-4">
      <VelocityMarquee
        ref={marqueeRef}
        text="SPRING INERTIA VELOCITY MARQUEE"
        className="text-2xl font-semibold tracking-tight"
      />
      <div className="flex gap-2">
        <button type="button" onClick={() => marqueeRef.current?.impulse(1200)}>
          Boost forward
        </button>
        <button type="button" onClick={() => marqueeRef.current?.impulse(-1200)}>
          Boost reverse
        </button>
        <button type="button" onClick={() => marqueeRef.current?.reset()}>
          Reset
        </button>
      </div>
    </div>
  );
}

Accessibility and reduced motion

Only the first marquee segment is exposed to assistive technology; every repeated clone carries aria-hidden="true" so screen readers announce the content once rather than repeating it. Combine pauseOnHover (active on fine pointers) with a visible toggle wired to paused to let users pause moving content at any time (WCAG 2.2.2).

The animation loop pauses automatically and clears will-change whenever the marquee leaves the viewport (IntersectionObserver) or the browser tab is hidden (visibilitychange), while speed scales with the global Kinetic tempo. Under reduced motion, VelocityMarquee stops its loop, ignores scroll velocity and impulse(), clears transforms, and renders static readable text.

API Reference

VelocityMarquee

Scroll-coupled horizontal marquee with spring-damped velocity, dynamic skewX, and accessible pause controls.

PropTypeDefaultDescription
textstring-Repeated marquee phrase (alternative to children).
baseVelocitynumber48Baseline horizontal travel speed in pixels per second.
velocityFactornumber0.45Multiplier mapping scroll speed into extra marquee speed.
maxSkewDegnumber14Maximum skewX tilt in degrees.
reverseOnScrollbooleantrueFlips marquee travel direction when scroll direction reverses.
pauseOnHoverbooleantruePauses drift while a fine pointer hovers the track.
pausedbooleanfalseControlled pause state for WCAG 2.2.2 compliance.
scrollContainerRefReact.RefObject<HTMLElement | null>-Optional local scroll container to measure velocity from in addition to window.