Getting Started
Components
Special Effects
Animations
Text Animations
Backgrounds
A component that animates content with blur and fade effects, supporting directional movement and intersection observer triggering.
motion-sv
Welcome to BlurFade
Beautiful blur and fade animations for your content
blur-fade.svelte
<script lang="ts"> import { BlurFade } from "$lib/components/magic/blur-fade/index.js";</script>
<div class="flex flex-col items-center justify-center gap-4 rounded-lg border p-8"> <BlurFade delay={0}> <h3 class="text-3xl font-bold text-black dark:text-white">Welcome to BlurFade</h3> </BlurFade> <BlurFade delay={0.2}> <p class="text-lg text-slate-600 dark:text-slate-300"> Beautiful blur and fade animations for your content </p> </BlurFade></div>Installation
pnpm dlx shadcn-svelte@latest add https://sv-animations.vercel.app/r/blur-fade.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:
blur-fade.svelte
<script lang="ts"> import type { ClassValue } from "svelte/elements"; import { motion, AnimatePresence, useInView, type Variants } from "motion-sv"; import { cn } from "#lib/utils.js"; import type { Snippet } from "svelte";
type MarginType = string;
interface BlurFadeProps { children: Snippet; class?: ClassValue; variant?: Variants; exit?: boolean; duration?: number; delay?: number; offset?: number; direction?: "up" | "down" | "left" | "right"; triggerOnView?: boolean; inViewMargin?: MarginType; blur?: string; once?: boolean; }
let { children, class: className, variant, exit = false, duration = 0.4, delay = 0, offset = 6, direction = "down", triggerOnView = true, inViewMargin = "-50px", blur = "6px", once = true, }: BlurFadeProps = $props();
let containerRef: HTMLDivElement | null = $state(null); let view = useInView( () => containerRef!, () => ({ once, amount: 0.1, margin: inViewMargin, }) as any );
const defaultVariants = $derived.by(() => { return { hidden: { [direction === "left" || direction === "right" ? "x" : "y"]: direction === "right" || direction === "down" ? -offset : offset, opacity: 0, filter: `blur(${blur})`, }, visible: { [direction === "left" || direction === "right" ? "x" : "y"]: 0, opacity: 1, filter: `blur(0px)`, }, } as Variants; });
const combinedVariants = $derived(variant || defaultVariants); const shouldAnimate = $derived(!triggerOnView || view.current);</script>
<div bind:this={containerRef}> <AnimatePresence> <motion.div initial="hidden" animate={shouldAnimate ? "visible" : "hidden"} exit={exit ? "hidden" : undefined} variants={combinedVariants} transition={{ delay: 0.04 + delay, duration, ease: "easeOut", }} class={cn(className)} > {@render children()} </motion.div> </AnimatePresence></div> index.ts
export { default as BlurFade } from "./blur-fade.svelte";Folder Structure
Folder Structure
src/└── lib/ └── components/ └── magic/ └── blur-fade/ ├── blur-fade.svelte └── index.tsInstall and integrate the Svelte component documented below.https://sv-animations.vercel.app/magic/docs/components/blur-fade/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 { BlurFade } from "#lib/components/magic/blur-fade/index.js";</script>
<BlurFade> <h2 class="text-3xl font-bold">Fade into view</h2></BlurFade>Examples
Basic Usage
Welcome to BlurFade
Beautiful blur and fade animations for your content
blur-fade-basic.svelte
<script lang="ts"> import { BlurFade } from "$lib/components/magic/blur-fade/index.js";</script>
<div class="flex flex-col items-center justify-center gap-4 rounded-lg border p-8"> <BlurFade delay={0}> <h3 class="text-3xl font-bold text-black dark:text-white">Welcome to BlurFade</h3> </BlurFade> <BlurFade delay={0.2}> <p class="text-lg text-slate-600 dark:text-slate-300"> Beautiful blur and fade animations for your content </p> </BlurFade></div>Custom Blur Amount
Light Blur
blur="2px"
Medium Blur
blur="6px" (default)
Heavy Blur
blur="12px"
blur-fade-custom-blur-amount.svelte
<script lang="ts"> import { BlurFade } from "$lib/components/magic/blur-fade/index.js";</script>
<div class="grid grid-cols-1 gap-6 md:grid-cols-3"> <BlurFade blur="2px" delay={0}> <div class="rounded-lg border p-6"> <h4 class="font-semibold text-black dark:text-white">Light Blur</h4> <p class="text-sm text-slate-600 dark:text-slate-300">blur="2px"</p> </div> </BlurFade> <BlurFade blur="6px" delay={0.1}> <div class="rounded-lg border p-6"> <h4 class="font-semibold text-black dark:text-white">Medium Blur</h4> <p class="text-sm text-slate-600 dark:text-slate-300">blur="6px" (default)</p> </div> </BlurFade> <BlurFade blur="12px" delay={0.2}> <div class="rounded-lg border p-6"> <h4 class="font-semibold text-black dark:text-white">Heavy Blur</h4> <p class="text-sm text-slate-600 dark:text-slate-300">blur="12px"</p> </div> </BlurFade></div>Image Gallery
blur-fade-image-gallery.svelte
<script lang="ts"> import { BlurFade } from "$lib/components/magic/blur-fade/index.js";
const images = Array.from({ length: 9 }, (_, i) => { const isLandscape = i % 2 === 0; const width = isLandscape ? 800 : 600; const height = isLandscape ? 600 : 800; return `https://picsum.photos/seed/${i + 1}/${width}/${height}`; });</script>
<div class="columns-2 gap-4 sm:columns-3"> {#each images as imageUrl, idx (imageUrl)} <BlurFade delay={0.25 + idx * 0.05} triggerOnView> <img class="mb-4 size-full rounded-lg object-contain" src={imageUrl} alt="Random stock image {idx + 1}" /> </BlurFade> {/each}</div>Props
Blur Fade
A component for creating blur and fade animations.
| Name | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The content to animate |
class | ClassValue | "" | Additional CSS classes to apply |
variant | Variants | - | Custom animation variants |
duration | number | 0.4 | Animation duration in seconds |
delay | number | 0 | Animation delay in seconds |
offset | number | 6 | Movement offset in pixels |
direction | "up" | "down" | "left" | "right" | "down" | Animation direction |
inView | boolean | false | Whether to trigger animation on intersection |
inViewMargin | string | "-50px" | Intersection observer margin |
blur | string | "6px" | Blur amount |