Border Beam
svelte-animations/border-beamFreeBlock
A component for creating animated border beam effects around elements with customizable gradients, duration, and direction.
Install it
npx shadcn@latest add https://sv-animations.vercel.app/r/border-beam.jsonSource
1<script lang="ts">2 import { motion, type Transition } from "motion-sv";3 import { cn } from "$UTILS$";45 interface BorderBeamProps {6 size?: number;7 duration?: number;8 delay?: number;9 colorFrom?: string;10 colorTo?: string;11 transition?: Transition;12 class?: string;13 style?: string;14 reverse?: boolean;15 initialOffset?: number;16 borderWidth?: number;17 }1819 let {20 class: className,21 size = 50,22 delay = 0,23 duration = 6,24 colorFrom = "#ffaa40",25 colorTo = "#9c40ff",26 transition,27 reverse = false,28 initialOffset = 0,29 borderWidth = 1,30 }: BorderBeamProps = $props();3132 const containerStyle = $derived(`--border-beam-width: ${borderWidth}px;`);3334 const beamStyle = $derived({35 width: size,36 offsetPath: `rect(0 auto auto 0 round ${size}px)`,37 "--color-from": colorFrom,38 "--color-to": colorTo,39 } as any);4041 const animateConfig = $derived({42 offsetDistance: reverse43 ? [`${100 - initialOffset}%`, `${-initialOffset}%`]44 : [`${initialOffset}%`, `${100 + initialOffset}%`],45 });4647 const transitionConfig = $derived({48 repeat: Infinity,49 ease: "linear" as const,50 duration,51 delay: -delay,52 ...transition,53 } as any);54</script>5556<div57 class="pointer-events-none absolute inset-0 rounded-[inherit] border-(length:--border-beam-width) border-transparent mask-[linear-gradient(transparent,transparent),linear-gradient(#000,#000)] mask-intersect [mask-clip:padding-box,border-box]"58 style={containerStyle}59>60 <motion.div61 class={cn(62 "absolute aspect-square",63 "bg-linear-to-l from-(--color-from) via-(--color-to) to-transparent",64 className65 )}66 style={beamStyle}67 initial={{ offsetDistance: `${initialOffset}%` }}68 animate={animateConfig}69 transition={transitionConfig}70 />71</div>
What it pulls in
npm packages
Files it writes
More from Svelte Animations
All 66 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Beamanimated-beam | Svelte Animations | Blocks | Free | 1 dep · 6 files | |
| Animated Circular Progress Baranimated-circular-progress-bar | Svelte Animations | Blocks | Free | no deps · 2 files | |
| Animated Gradient Textanimated-gradient-text | Svelte Animations | Blocks | Free | no deps · 2 files | |
| Animated Grid Patternanimated-grid-pattern | Svelte Animations | Blocks | Free | 1 dep · 2 files | |
| Animated Listanimated-list | Svelte Animations | Blocks | Free | 1 dep · 2 files | |
| Animated Shiny Textanimated-shiny-text | Svelte Animations | Blocks | Free | no deps | |
| Animated Theme Toggleranimated-theme-toggler | Svelte Animations | Blocks | Free | no deps · 2 files | |
| Arc Timelinearc-timeline | Svelte Animations | Blocks | Free | no deps · 3 files |
