Modus UI

Animated Beam

Web (React)

A dynamic SVG beam animation that traces paths between elements.

A beautiful component that shoots a glowing gradient pulse along an SVG path connecting two HTML elements. It mathematically calculates the path curves automatically based on the live geometry and position of the DOM nodes using ResizeObserver.

💻
📦
🚀
☁️

Installation

CLI

npx @modus-ui/cli add animated-beam

Manual

  1. Copy the code from the component tab.
  2. Create a file at components/ui/animated-beam.tsx.
  3. Paste the code.

Usage

tsx
import { useRef } from "react";
import { AnimatedBeam } from "@/components/ui/animated-beam";

export default function Example() {
  const containerRef = useRef<HTMLDivElement>(null);
  const fromRef = useRef<HTMLDivElement>(null);
  const toRef = useRef<HTMLDivElement>(null);

  return (
    <div ref={containerRef} className="relative flex justify-between p-10">
      <div ref={fromRef}>Node A</div>
      <div ref={toRef}>Node B</div>
      <AnimatedBeam containerRef={containerRef} fromRef={fromRef} toRef={toRef} curvature={-50} />
    </div>
  );
}

Props

PropTypeDefaultDescription
containerRefRefObject<HTMLElement | null>-The container both elements sit in.
fromRefRefObject<HTMLElement | null>-The element the beam starts at.
toRefRefObject<HTMLElement | null>-The element the beam ends at.
curvaturenumber0Bend of the path in pixels.
reversebooleanfalseRuns the beam from end to start.
durationnumber3Seconds for one beam pass.
delaynumber0Seconds before the beam starts.
pathColorstring"hsl(var(--border))"Colour of the static path.
gradientStartstring"hsl(var(--primary))"Start colour of the beam.
gradientStopstring"hsl(var(--primary))"End colour of the beam.

Comments

  • No comments yet.