Getting Started
Components
Special Effects
Animations
Text Animations
Backgrounds
An animated ripple effect typically used behind elements to emphasize them.
Ripple
ripple.svelte
<script lang="ts"> import { Ripple } from "$lib/components/magic/ripple/index.js";</script>
<div class="bg-background relative flex h-[500px] w-full flex-col items-center justify-center overflow-hidden rounded-lg border"> <p class="z-10 text-center text-5xl font-medium tracking-tighter whitespace-pre-wrap text-white" > Ripple </p> <Ripple /></div>Installation
pnpm dlx shadcn-svelte@latest add https://sv-animations.vercel.app/r/ripple.json
Copy the Source Code
Copy and paste the following code into your project:
ripple.svelte
<script lang="ts"> import { cn } from "#lib/utils.js"; import type { ClassValue, HTMLAttributes } from "svelte/elements";
interface RippleProps extends HTMLAttributes<HTMLDivElement> { mainCircleSize?: number; mainCircleOpacity?: number; numCircles?: number; class?: ClassValue; }
let { mainCircleSize = 210, mainCircleOpacity = 0.24, numCircles = 8, class: className, ...props }: RippleProps = $props();</script>
<div class={cn( "pointer-events-none absolute inset-0 mask-[linear-gradient(to_bottom,white,transparent)] select-none", className )} {...props}> {#each Array.from({ length: numCircles }) as _, i} {@const size = mainCircleSize + i * 70} {@const opacity = mainCircleOpacity - i * 0.03} {@const animationDelay = `${i * 0.06}s`} <div class="animate-ripple bg-foreground/25 absolute rounded-full border shadow-xl" style=" --i: {i}; width: {size}px; height: {size}px; opacity: {opacity}; animation-delay: {animationDelay}; border-style: solid; border-width: 1px; border-color: var(--foreground); top: 50%; left: 50%; transform: translate(-50%, -50%) scale(1);" ></div> {/each}</div>
<!--style:--i={i} style:width="{size}px" style:height="{size}px" style:opacity style:animation-delay={animationDelay} style:border-style="solid" style:border-width="1px" style:border-color="var(--foreground)" style:top="50%" style:left="50%" style:transform="translate(-50%, -50%) scale(1)" --> index.ts
import Ripple from "./ripple.svelte";export { Ripple };Add Tailwind CSS
Add the following to your routes/layout.css file:
src/routes/layout.css
@theme inline { --animate-ripple: ripple var(--duration, 2s) ease calc(var(--i, 0) * 0.2s) infinite;
@keyframes ripple { 0%, 100% { transform: translate(-50%, -50%) scale(1); } 50% { transform: translate(-50%, -50%) scale(0.9); } }}Folder Structure
Folder Structure
src/└── lib/ └── components/ └── magic/ └── ripple/ ├── ripple.svelte └── index.tsInstall and integrate the Svelte component documented below.https://sv-animations.vercel.app/magic/docs/components/ripple/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 { Ripple } from "#lib/components/magic/ripple/index.js";</script>
<div class="relative h-64 overflow-hidden"> <Ripple /></div>Props
Ripple
A component for Ripple.
| Name | Type | Default | Description |
|---|---|---|---|
class | ClassValue | "" | Additional CSS classes to apply |
mainCircleSize | number | 210 | The size of the main circle |
mainCircleOpacity | number | 0.24 | The opacity of the main circle |
numCircles | number | 8 | The number of ripple circles |