Skip to content
Effects Fancy Stable

AnimatedBeam

.md

Fibre-optic connector between two elements: a light packet with a dispersing chromatic tail runs along a glass fibre and blooms behind the destination on arrival; theme-aware, seeded and still under reduced motion.

Available for Svelte 5, React, and Vue 3.

Preview

Installation

pnpm add fancy-ui-svelte
import { AnimatedBeam } from "fancy-ui-svelte";

Usage

svelte
<script lang="ts">
	import { AnimatedBeam } from "fancy-ui-svelte";
	import FileText from "@lucide/svelte/icons/file-text";
	import Database from "@lucide/svelte/icons/database";
	import MessageSquare from "@lucide/svelte/icons/message-square";
	import Sparkles from "@lucide/svelte/icons/sparkles";
	import User from "@lucide/svelte/icons/user";

	let containerRef = $state<HTMLElement>();
	let docsRef = $state<HTMLElement>();
	let dataRef = $state<HTMLElement>();
	let chatRef = $state<HTMLElement>();
	let hubRef = $state<HTMLElement>();
	let userRef = $state<HTMLElement>();

	// Nested frame: a hairline shell around a darker inner well.
	const node =
		"relative z-10 rounded-2xl border border-black/[0.08] bg-[#fafafa] p-1 shadow-[0_1px_2px_rgba(0,0,0,0.06)] dark:border-white/[0.08] dark:bg-[#141416] dark:shadow-none";
	const well =
		"flex items-center justify-center rounded-xl border border-black/[0.06] bg-white text-neutral-700 dark:border-white/[0.06] dark:bg-[#0b0b0c] dark:text-neutral-300";
</script>

<div
	class="w-full rounded-[22px] border border-black/[0.08] bg-[#f4f4f5] p-1.5 dark:border-white/[0.08] dark:bg-[#0b0b0c]"
>
	<div
		bind:this={containerRef}
		class="relative flex h-[420px] w-full items-center justify-center overflow-hidden rounded-2xl border border-black/[0.06] bg-[#fafafa] dark:border-white/[0.06] dark:bg-[#111113]"
	>
		<!-- faint dot field -->
		<div
			aria-hidden="true"
			class="pointer-events-none absolute inset-0 [background-image:radial-gradient(rgba(0,0,0,0.07)_1px,transparent_1px)] [mask-image:radial-gradient(ellipse_at_center,black,transparent_75%)] [background-size:18px_18px] dark:[background-image:radial-gradient(rgba(255,255,255,0.06)_1px,transparent_1px)]"
		></div>

		<div class="flex w-full max-w-xl items-center justify-between px-8 sm:px-12">
			<div class="flex flex-col gap-10">
				<div bind:this={docsRef} class={node}>
					<div class="{well} size-11"><FileText class="size-[18px]" strokeWidth={1.6} /></div>
				</div>
				<div bind:this={dataRef} class={node}>
					<div class="{well} size-11"><Database class="size-[18px]" strokeWidth={1.6} /></div>
				</div>
				<div bind:this={chatRef} class={node}>
					<div class="{well} size-11"><MessageSquare class="size-[18px]" strokeWidth={1.6} /></div>
				</div>
			</div>

			<div bind:this={hubRef} class="{node} rounded-[22px] p-1.5">
				<div class="{well} size-16 rounded-[16px]">
					<Sparkles class="size-6" strokeWidth={1.5} />
				</div>
			</div>

			<div bind:this={userRef} class={node}>
				<div class="{well} size-11"><User class="size-[18px]" strokeWidth={1.6} /></div>
			</div>
		</div>

		{#if containerRef && hubRef}
			{#if docsRef}
				<AnimatedBeam
					{containerRef}
					fromRef={docsRef}
					toRef={hubRef}
					curvature={-60}
					endYOffset={-12}
					gradientStartColor="#f2b880"
					gradientStopColor="#a78bfa"
					seed={3}
				/>
			{/if}
			{#if dataRef}
				<AnimatedBeam
					{containerRef}
					fromRef={dataRef}
					toRef={hubRef}
					gradientStartColor="#f2b880"
					gradientStopColor="#a78bfa"
					seed={7}
					delay={0.9}
				/>
			{/if}
			{#if chatRef}
				<AnimatedBeam
					{containerRef}
					fromRef={chatRef}
					toRef={hubRef}
					curvature={60}
					endYOffset={12}
					gradientStartColor="#f2b880"
					gradientStopColor="#a78bfa"
					seed={11}
					delay={1.7}
				/>
			{/if}
			{#if userRef}
				<AnimatedBeam
					{containerRef}
					fromRef={hubRef}
					toRef={userRef}
					gradientStartColor="#f2b880"
					gradientStopColor="#a78bfa"
					seed={5}
					delay={2.4}
				/>
			{/if}
		{/if}
	</div>
</div>

Examples

Basic Usage

Three fibres converge on a hub that feeds a fourth; packets arrive and bloom.

Dispersion

Three packets in flight with a long cool tail and strong glow, and a short warm tail run in reverse.

Props

PropTypeDefaultDescription
containerRef *HTMLElement-Reference to the container element that holds both endpoints
fromRef *HTMLElement-Reference to the source element
toRef *HTMLElement-Reference to the destination element
curvature number0Vertical curvature of the beam path
reverse booleanfalseReverse the animation direction
pathColor stringtheme-aware glassCHANGED DEFAULT (was "gray"): unset draws the theme-aware glass fibre; a colour draws a plain line in that colour, as before.
pathWidth number2Stroke width of the path
pathOpacity number1 (glass) / 0.2 (with pathColor)CHANGED DEFAULT (was 0.2): fibre opacity; stays 0.2 whenever pathColor is set.
gradientStartColor string"#FFAA40"Start color of the animated gradient
gradientStopColor string"#9C40FF"End color of the animated gradient
delay number0Animation delay in seconds
duration numberfrom seedCHANGED DEFAULT (was random): seconds per packet cycle; unset = mulberry32(seed)*3+4.
pulses number1Packets in flight at once (1–12), spaced evenly over one cycle.
tail number0.35Length of the packet's dispersing tail as a fraction of the fibre (0.05–0.9).
glow number0.6Strength of the blurred glow under the packet and of the arrival bloom (0–1).
seed number1Seed for the default duration (between 4 and 7 s), so server and browser agree.
startXOffset number0Horizontal offset for the start point
startYOffset number0Vertical offset for the start point
endXOffset number0Horizontal offset for the end point
endYOffset number0Vertical offset for the end point