Animated Beam

An animated beam of light which travels along a path. Useful for showcasing the "integration" features of a website.

motion-sv

Installation

pnpm dlx shadcn-svelte@latest add https://sv-animations.vercel.app/r/animated-beam.json

Usage

<script lang="ts">	import { AnimatedBeam } from "#lib/components/magic/animated-beam/index.js";
	let containerRef: HTMLDivElement | null = $state(null);	let fromRef: HTMLDivElement | null = $state(null);	let toRef: HTMLDivElement | null = $state(null);</script>
<div class="relative flex h-24 w-64 items-center justify-between" bind:this={containerRef}>	<div class="size-3 rounded-full bg-current" bind:this={fromRef}></div>	<div class="size-3 rounded-full bg-current" bind:this={toRef}></div>	<AnimatedBeam {containerRef} {fromRef} {toRef} /></div>

Examples

With Curvature

Reverse Direction

Bi Directional Beams

Multiple Beams Inputs

Multiple Beams Outputs

Merge Four Files

Four file nodes merge into a bundle through curved, staggered monochrome beams.

page.svelte
config.json
styles.css
utils.ts
bundle.js

Publish Workflow

A push flows through a build to preview and checks with a single status accent.

push
build
preview
checks

Props

Animated Beam

A component for creating animated beam effects between elements.

NameTypeDefaultDescription
classstring""Additional CSS classes to apply
containerRefHTMLElement | nullnullReference to the container element
fromRefHTMLElement | nullnullReference to the starting element
toRefHTMLElement | nullnullReference to the ending element
curvaturenumber0Curvature of the beam path
reversebooleanfalseReverse the animation direction
durationnumberMath.random() * 3 + 4Duration of the animation in seconds
delaynumber0Delay before animation starts
pathColorstring"gray"Color of the beam path
pathWidthnumber2Width of the beam path
pathOpacitynumber0.2Opacity of the beam path
gradientStartColorstring"#ffaa40"Starting color of the gradient
gradientStopColorstring"#9c40ff"Ending color of the gradient
startXOffsetnumber0X offset for the start position
startYOffsetnumber0Y offset for the start position
endXOffsetnumber0X offset for the end position
endYOffsetnumber0Y offset for the end position