Light Rays
svelte-animations/light-raysFreeBlock
A component that creates animated light rays with customizable count, color, blur, speed, and length.
Install it
npx shadcn@latest add https://sv-animations.vercel.app/r/light-rays.jsonSource
1<script lang="ts">2 import { motion } from "motion-sv";3 import { cn } from "$UTILS$";45 interface LightRay {6 id: string;7 left: number;8 rotate: number;9 width: number;10 swing: number;11 delay: number;12 duration: number;13 intensity: number;14 }1516 interface LightRaysProps {17 class?: string;18 count?: number;19 color?: string;20 blur?: number;21 speed?: number;22 length?: string;23 style?: string;24 }2526 let {27 class: className,28 count = 7,29 color = "rgba(160, 210, 255, 0.2)",30 blur = 36,31 speed = 14,32 length = "70vh",33 style,34 ...props35 }: LightRaysProps = $props();3637 let rays = $state<LightRay[]>([]);38 let cycleDuration = $derived(Math.max(speed, 0.1));3940 let createRays = (count: number, cycle: number): LightRay[] => {41 if (count <= 0) return [];4243 return Array.from({ length: count }, (_, index) => {44 const left = 8 + Math.random() * 84;45 const rotate = -28 + Math.random() * 56;46 const width = 160 + Math.random() * 160;47 const swing = 0.8 + Math.random() * 1.8;48 const delay = Math.random() * cycle;49 const duration = cycle * (0.75 + Math.random() * 0.5);50 const intensity = 0.6 + Math.random() * 0.5;5152 return {53 id: `${index}-${Math.round(left * 10)}`,54 left,55 rotate,56 width,57 swing,58 delay,59 duration,60 intensity,61 };62 });63 };6465 // onMount(() => {66 // rays = createRays(count, cycleDuration);67 // });6869 $effect(() => {70 rays = createRays(count, cycleDuration);71 });72</script>7374<div75 class={cn(76 "pointer-events-none absolute inset-0 isolate overflow-hidden rounded-[inherit]",77 className78 )}79 style="--light-rays-color: {color}; --light-rays-blur: {blur}px; --light-rays-length: {length}; {style ||80 ''}"81 {...props}82>83 <div class="absolute inset-0 overflow-hidden">84 <div85 aria-hidden="true"86 class="absolute inset-0 opacity-60"87 style="background: radial-gradient(circle at 20% 15%, color-mix(in srgb, var(--light-rays-color) 45%, transparent), transparent 70%)"88 ></div>89 <div90 aria-hidden="true"91 class="absolute inset-0 opacity-60"92 style="background: radial-gradient(circle at 80% 10%, color-mix(in srgb, var(--light-rays-color) 35%, transparent), transparent 75%)"93 ></div>94 {#each rays as ray (ray.id)}95 <motion.div96 class="pointer-events-none absolute -top-[12%] h-(--light-rays-length) origin-top -translate-x-1/2 rounded-full bg-linear-to-b from-[color-mix(in_srgb,var(--light-rays-color)_70%,transparent)] to-transparent opacity-0 mix-blend-screen blur-(--light-rays-blur)"97// … truncated
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 |
