Getting Started
Components
Special Effects
Animations
Text Animations
Backgrounds
A component that creates a progressive blur effect at the top, bottom, or both edges of a container with customizable blur levels and positioning.
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
progressive-blur.svelte
<script> import { ProgressiveBlur } from "$lib/components/magic/progressive-blur/index.js"; import { ScrollArea } from "$lib/components/ui/scroll-area/index.js";</script>
<div class="relative w-full rounded-xl border"> <ScrollArea fadeEffect={false} class="relative h-100 overflow-hidden"> <div class="flex flex-col gap-2 p-4"> {#each { length: 20 } as _, index} <div class="bg-card flex h-20 w-full items-center justify-center rounded-xl border"> {index} </div> {/each} </div> <ProgressiveBlur position="bottom" height="40%" /> </ScrollArea></div>Installation
pnpm dlx shadcn-svelte@latest add https://sv-animations.vercel.app/r/progressive-blur.json
Copy the Source Code
Copy and paste the following code into your project:
progressive-blur.svelte
<script lang="ts"> import { cn } from "#lib/utils.js"; import type { ClassValue, HTMLAttributes } from "svelte/elements";
interface ProgressiveBlurProps extends HTMLAttributes<HTMLDivElement> { /** * Additional CSS classes */ class?: ClassValue; /** * Height of the blur area */ height?: string; /** * Position of the blur effect */ position?: "top" | "bottom" | "both"; /** * Array of blur levels in pixels */ blurLevels?: number[]; }
let { class: className, height = "30%", position = "bottom", blurLevels = [0.5, 1, 2, 4, 8, 16, 32, 64], ...props }: ProgressiveBlurProps = $props();
// Create array with length equal to blurLevels.length - 2 (for before/after pseudo elements) const divElements = $derived(Array(blurLevels.length - 2).fill(null));
const getMaskGradient = (index: number) => { const blurIndex = index + 1; const startPercent = blurIndex * 12.5; const midPercent = (blurIndex + 1) * 12.5; const endPercent = (blurIndex + 2) * 12.5;
if (position === "bottom") { return `linear-gradient(to bottom, rgba(0,0,0,0) ${startPercent}%, rgba(0,0,0,1) ${midPercent}%, rgba(0,0,0,1) ${endPercent}%, rgba(0,0,0,0) ${endPercent + 12.5}%)`; } else if (position === "top") { return `linear-gradient(to top, rgba(0,0,0,0) ${startPercent}%, rgba(0,0,0,1) ${midPercent}%, rgba(0,0,0,1) ${endPercent}%, rgba(0,0,0,0) ${endPercent + 12.5}%)`; } else { return `linear-gradient(rgba(0,0,0,0) 0%, rgba(0,0,0,1) 5%, rgba(0,0,0,1) 95%, rgba(0,0,0,0) 100%)`; } };
const getFirstLayerMask = () => { if (position === "bottom") { return `linear-gradient(to bottom, rgba(0,0,0,0) 0%, rgba(0,0,0,1) 12.5%, rgba(0,0,0,1) 25%, rgba(0,0,0,0) 37.5%)`; } else if (position === "top") { return `linear-gradient(to top, rgba(0,0,0,0) 0%, rgba(0,0,0,1) 12.5%, rgba(0,0,0,1) 25%, rgba(0,0,0,0) 37.5%)`; } else { return `linear-gradient(rgba(0,0,0,0) 0%, rgba(0,0,0,1) 5%, rgba(0,0,0,1) 95%, rgba(0,0,0,0) 100%)`; } };
const getLastLayerMask = () => { if (position === "bottom") { return `linear-gradient(to bottom, rgba(0,0,0,0) 87.5%, rgba(0,0,0,1) 100%)`; } else if (position === "top") { return `linear-gradient(to top, rgba(0,0,0,0) 87.5%, rgba(0,0,0,1) 100%)`; } else { return `linear-gradient(rgba(0,0,0,0) 0%, rgba(0,0,0,1) 5%, rgba(0,0,0,1) 95%, rgba(0,0,0,0) 100%)`; } };</script>
<div class={cn( "gradient-blur pointer-events-none absolute inset-x-0 z-10", className, position === "top" ? "top-0" : position === "bottom" ? "bottom-0" : "inset-y-0" )} style:height={position === "both" ? "100%" : height} {...props}> <!-- First blur layer --> <div class="absolute inset-0" style:z-index={1} style:backdrop-filter="blur({blurLevels[0]}px)" style:-webkit-backdrop-filter="blur({blurLevels[0]}px)" style:mask-image={getFirstLayerMask()} style:-webkit-mask-image={getFirstLayerMask()} ></div>
<!-- Middle blur layers --> {#each divElements as _, index (index)} {@const blurIndex = index + 1} {@const maskGradient = getMaskGradient(index)} <div class="absolute inset-0" style:z-index={index + 2} style:backdrop-filter="blur({blurLevels[blurIndex]}px)" style:-webkit-backdrop-filter="blur({blurLevels[blurIndex]}px)" style:mask-image={maskGradient} style:-webkit-mask-image={maskGradient} ></div> {/each}
<!-- Last blur layer --> <div class="absolute inset-0" style:z-index={blurLevels.length} style:backdrop-filter="blur({blurLevels[blurLevels.length - 1]}px)" style:-webkit-backdrop-filter="blur({blurLevels[blurLevels.length - 1]}px)" style:mask-image={getLastLayerMask()} style:-webkit-mask-image={getLastLayerMask()} ></div></div> index.ts
export { default as ProgressiveBlur } from "./progressive-blur.svelte";Folder Structure
Folder Structure
src/└── lib/ └── components/ └── magic/ └── progressive-blur/ ├── progressive-blur.svelte └── index.tsInstall and integrate the Svelte component documented below.https://sv-animations.vercel.app/magic/docs/components/progressive-blur/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 { ProgressiveBlur } from "#lib/components/magic/progressive-blur/index.js";</script>
<div class="relative h-64 overflow-hidden"> <div class="h-full overflow-auto">Scrollable content</div> <ProgressiveBlur position="bottom" /></div>Props
Progressive Blur
A component that creates a progressive blur effect with customizable positioning and blur levels.
| Name | Type | Default | Description |
|---|---|---|---|
class | ClassValue | "" | Additional CSS classes to apply |
height | string | "30%" | Height of the blur area |
position | "top" | "bottom" | "both" | "bottom" | Position of the blur effect |
blurLevels | number[] | [0.5, 1, 2, 4, 8, 16, 32, 64] | Array of blur levels in pixels for progressive blur layers |