Ripple
An animated ripple effect typically used behind elements to emphasize them.
Ripple
Installation
Copy and paste the following code into your project.
import React, { CSSProperties } from "react"
interface RippleProps {
mainCircleSize?: number
mainCircleOpacity?: number
numCircles?: number
}
const Ripple = React.memo(function Ripple({
mainCircleSize = 210,
mainCircleOpacity = 0.24,
numCircles = 8,
}: RippleProps) {
return (
<div className="absolute inset-0 flex items-center justify-center bg-white/5 [mask-image:linear-gradient(to_bottom,white,transparent)]">
{Array.from({ length: numCircles }, (_, i) => {
const size = mainCircleSize + i * 70
const opacity = mainCircleOpacity - i * 0.03
const animationDelay = `${i * 0.06}s`
const borderStyle = i === numCircles - 1 ? "dashed" : "solid"
const borderOpacity = 5 + i * 5
return (
<div
key={i}
className={`absolute animate-ripple rounded-full bg-foreground/25 shadow-xl border [--i:${i}]`}
style={
{
width: `${size}px`,
height: `${size}px`,
opacity,
animationDelay,
borderStyle,
borderWidth: "1px",
borderColor: `hsl(var(--foreground), ${borderOpacity / 100})`,
top: "50%",
left: "50%",
transform: "translate(-50%, -50%) scale(1)",
} as CSSProperties
}
/>
)
})}
</div>
)
})
Ripple.displayName = "Ripple"
export { Ripple }
Update the import paths to match your project setup.
Update tailwind.config.js
Add the following animations to your tailwind.config.js
file:
tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
extend: {
animation: {
ripple: "ripple var(--duration,2s) ease calc(var(--i, 0)*.2s) infinite",
},
keyframes: {
ripple: {
"0%, 100%": {
transform: "translate(-50%, -50%) scale(1)",
},
"50%": {
transform: "translate(-50%, -50%) scale(0.9)",
},
},
},
},
},
}
Props
Prop | Type | Default | Description |
---|---|---|---|
mainCircleSize | number | 210 | The size of the main circle in pixels |
mainCircleOpacity | number | 0.24 | The opacity of the main circle |
numCircles | number | 8 | The number of ripple circles to render |