Getting Started
Components
Special Effects
Animations
Text Animations
Backgrounds
A component with animated light rays which shine down from above.
motion-sv
Ambient glow
Light Rays
Drop this component into any container and it will fill the space with softly animated light rays shining from above.
light-rays.svelte
<script lang="ts"> import { LightRays } from "$lib/components/magic/light-rays/index.js";</script>
<div class="relative h-125 w-full overflow-hidden rounded-lg border"> <div class="relative z-10 flex h-full flex-col items-center justify-center gap-4 px-6 text-center" > <span class="text-xs font-semibold tracking-[0.35em] text-slate-800/60 uppercase dark:text-slate-200/60" > Ambient glow </span> <h2 class="text-foreground text-4xl font-bold md:text-5xl">Light Rays</h2> <p class="max-w-md text-sm text-slate-800/80 md:text-base dark:text-slate-200/80"> Drop this component into any container and it will fill the space with softly animated light rays shining from above. </p> </div> <LightRays /></div>Installation
pnpm dlx shadcn-svelte@latest add https://sv-animations.vercel.app/r/light-rays.json
Install dependencies
Install the required packages for this component:
pnpm add motion-sv
Copy the Source Code
Copy and paste the following code into your project:
light-rays.svelte
<script lang="ts"> import type { ClassValue } from "svelte/elements"; import { motion } from "motion-sv"; import { cn } from "#lib/utils.js";
interface LightRay { id: string; left: number; rotate: number; width: number; swing: number; delay: number; duration: number; intensity: number; }
interface LightRaysProps { class?: ClassValue; count?: number; color?: string; blur?: number; speed?: number; length?: string; style?: string; }
let { class: className, count = 7, color = "rgba(160, 210, 255, 0.2)", blur = 36, speed = 14, length = "70vh", style, ...props }: LightRaysProps = $props();
let rays = $state<LightRay[]>([]); let cycleDuration = $derived(Math.max(speed, 0.1));
let createRays = (count: number, cycle: number): LightRay[] => { if (count <= 0) return [];
return Array.from({ length: count }, (_, index) => { const left = 8 + Math.random() * 84; const rotate = -28 + Math.random() * 56; const width = 160 + Math.random() * 160; const swing = 0.8 + Math.random() * 1.8; const delay = Math.random() * cycle; const duration = cycle * (0.75 + Math.random() * 0.5); const intensity = 0.6 + Math.random() * 0.5;
return { id: `${index}-${Math.round(left * 10)}`, left, rotate, width, swing, delay, duration, intensity, }; }); };
// onMount(() => { // rays = createRays(count, cycleDuration); // });
$effect(() => { rays = createRays(count, cycleDuration); });</script>
<div class={cn( "pointer-events-none absolute inset-0 isolate overflow-hidden rounded-[inherit]", className )} style="--light-rays-color: {color}; --light-rays-blur: {blur}px; --light-rays-length: {length}; {style || ''}" {...props}> <div class="absolute inset-0 overflow-hidden"> <div aria-hidden="true" class="absolute inset-0 opacity-60" style="background: radial-gradient(circle at 20% 15%, color-mix(in srgb, var(--light-rays-color) 45%, transparent), transparent 70%)" ></div> <div aria-hidden="true" class="absolute inset-0 opacity-60" style="background: radial-gradient(circle at 80% 10%, color-mix(in srgb, var(--light-rays-color) 35%, transparent), transparent 75%)" ></div> {#each rays as ray (ray.id)} <motion.div 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)" style={{ left: `${ray.left}%`, width: `${ray.width}px` }} initial={{ rotate: ray.rotate }} animate={{ opacity: [0, ray.intensity, 0], rotate: [ ray.rotate - ray.swing, ray.rotate + ray.swing, ray.rotate - ray.swing, ], }} transition={{ duration: ray.duration, repeat: Infinity, ease: "easeInOut", delay: ray.delay, repeatDelay: ray.duration * 0.1, }} /> {/each} </div></div> index.ts
import LightRays from "./light-rays.svelte";export { LightRays };Folder Structure
Folder Structure
src/└── lib/ └── components/ └── magic/ └── light-rays/ ├── light-rays.svelte └── index.tsInstall and integrate the Svelte component documented below.https://sv-animations.vercel.app/magic/docs/components/light-rays/llms.txt
Follow the guide's installation and usage instructions.Match the project's existing structure, imports, and styles.Keep changes scoped to the component and verify it works.Reply with a short bullet list of completed changes.Usage
<script lang="ts"> import { LightRays } from "#lib/components/magic/light-rays/index.js";</script>
<div class="relative h-80 overflow-hidden"> <LightRays /></div>Props
Light Rays
A component for Light Rays.
| Name | Type | Default | Description |
|---|---|---|---|
class | ClassValue | "" | Additional CSS classes to apply |
count | number | 7 | Number of light rays to render |
color | string | "rgba(160, 210, 255, 0.2)" | Color of the light rays |
blur | number | 36 | Blur of the light rays |
speed | number | 14 | Speed of the light rays |
length | string | "70vh" | Length of the light rays |
style | string | "" | Additional CSS styles to apply |