Getting Started
Components
Special Effects
Animations
Text Animations
Backgrounds
An animated button with ripple useful for user engagement.
runed
ripple-button.svelte
<script lang="ts"> import { RippleButton } from "$lib/components/magic/ripple-button/index.js";</script>
<RippleButton rippleColor="#ADD8E6">Click me</RippleButton>Installation
pnpm dlx shadcn-svelte@latest add https://sv-animations.vercel.app/r/ripple-button.json
Install dependencies
Install the required packages for this component:
pnpm add runed
Copy the Source Code
Copy and paste the following code into your project:
ripple-button.svelte
<script lang="ts"> import { cn } from "#lib/utils.js"; import { watch } from "runed"; import type { Snippet } from "svelte"; import type { ClassValue, HTMLButtonAttributes } from "svelte/elements";
interface RippleButtonProps extends HTMLButtonAttributes { children: Snippet; class?: ClassValue; rippleColor?: string; duration?: string; }
let { class: className, children, rippleColor = "#ffffff", duration = "600ms", onclick, ...props }: RippleButtonProps = $props();
let buttonRipples = $state<Array<{ x: number; y: number; size: number; key: number }>>([]);
const handleClick = (event: MouseEvent & { currentTarget: HTMLButtonElement }) => { createRipple(event); onclick?.(event); };
const createRipple = (event: MouseEvent & { currentTarget: HTMLButtonElement }) => { const button = event.currentTarget; const rect = button.getBoundingClientRect(); const size = Math.max(rect.width, rect.height); const x = event.clientX - rect.left - size / 2; const y = event.clientY - rect.top - size / 2;
const newRipple = { x, y, size, key: Date.now() }; buttonRipples = [...buttonRipples, newRipple]; };
watch([() => buttonRipples, () => duration], () => { if (buttonRipples.length > 0) { const lastRipple = buttonRipples[buttonRipples.length - 1]; const timeout = setTimeout(() => { buttonRipples = buttonRipples.filter((ripple) => ripple.key !== lastRipple.key); }, parseInt(duration)); return () => clearTimeout(timeout); } });</script>
<button class={cn( "bg-muted text-primary relative flex cursor-pointer items-center justify-center overflow-hidden rounded-lg border-2 px-4 py-2 text-center", className )} onclick={handleClick} {...props}> <div class="relative z-10"> {@render children()} </div> <span class="pointer-events-none absolute inset-0"> {#each buttonRipples as ripple} <span class="animate-rippling absolute rounded-full" style=" --duration: {duration}; width: {ripple.size}px; height: {ripple.size}px; top: {ripple.y}px; left: {ripple.x}px; background-color: {rippleColor}; transform: scale(0); " > </span> {/each} </span></button> index.ts
export { default as RippleButton } from "./ripple-button.svelte";Add Tailwind CSS
Add the following to your routes/layout.css file:
src/routes/layout.css
@theme inline { --animate-rippling: rippling var(--duration) ease-out;
@keyframes rippling { 0% { opacity: 1; } 100% { transform: scale(2); opacity: 0; } }}Folder Structure
Folder Structure
src/└── lib/ └── components/ └── magic/ └── ripple-button/ ├── ripple-button.svelte └── index.tsInstall and integrate the Svelte component documented below.https://sv-animations.vercel.app/magic/docs/components/ripple-button/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 { RippleButton } from "#lib/components/magic/ripple-button/index.js";</script>
<RippleButton>Click me</RippleButton>Examples
Tinted Buttons
Emerald and orange buttons with faint translucent fills and light text in dark mode.
ripple-button-tinted.svelte
<script lang="ts"> import { RippleButton } from "$lib/components/magic/ripple-button/index.js";</script>
<div class="flex flex-wrap items-center justify-center gap-4"> <RippleButton type="button" rippleColor="oklch(0.765 0.177 163.223 / 0.5)" class="border-emerald-300 bg-emerald-200 text-emerald-900 dark:border-emerald-400/20 dark:bg-emerald-400/10 dark:text-emerald-200" > Save changes </RippleButton> <RippleButton type="button" rippleColor="oklch(0.75 0.183 55.934 / 0.5)" class="border-orange-300 bg-orange-200 text-orange-900 dark:border-orange-400/20 dark:bg-orange-400/10 dark:text-orange-200" > Review changes </RippleButton></div>Button Sizes
Compact, default, and large buttons using padding and font-size utilities.
ripple-button-sizes.svelte
<script lang="ts"> import { RippleButton } from "$lib/components/magic/ripple-button/index.js";</script>
<div class="flex flex-wrap items-center justify-center gap-4"> <RippleButton type="button" rippleColor="#a3a3a3" class="px-3 py-1.5 text-sm" >Small</RippleButton > <RippleButton type="button" rippleColor="#a3a3a3" class="px-4 py-2 text-base" >Medium</RippleButton > <RippleButton type="button" rippleColor="#a3a3a3" class="px-6 py-3 text-lg">Large</RippleButton></div>Props
Ripple Button
A component for Ripple Button.
| Name | Type | Default | Description |
|---|---|---|---|
class | ClassValue | "" | Additional CSS classes to apply |
rippleColor | string | "#ffffff" | Color of the ripple effect |
duration | string | "600ms" | Duration of the ripple effect |
children | Snippet | required | The content of the button |