Blur Fade
Blur fade in and out animation. Used to smoothly fade in and out content.
Installation
Copy and paste the following code into your project.
"use client"
import { useRef } from "react"
import { AnimatePresence, Variants, motion, useInView } from "framer-motion"
interface BlurFadeProps {
children: React.ReactNode
className?: string
variant?: {
hidden: { y: number }
visible: { y: number }
}
duration?: number
delay?: number
yOffset?: number
inView?: boolean
inViewMargin?: string
blur?: string
}
export function BlurFade({
children,
className,
variant,
duration = 0.4,
delay = 0,
yOffset = 6,
inView = false,
inViewMargin = "-50px",
blur = "6px",
}: BlurFadeProps) {
const ref = useRef(null)
const inViewResult = useInView(ref, { once: true, margin: inViewMargin })
const isInView = !inView || inViewResult
const defaultVariants: Variants = {
hidden: { y: yOffset, opacity: 0, filter: `blur(${blur})` },
visible: { y: -yOffset, opacity: 1, filter: `blur(0px)` },
}
const combinedVariants = variant || defaultVariants
return (
<AnimatePresence>
<motion.div
ref={ref}
initial="hidden"
animate={isInView ? "visible" : "hidden"}
exit="hidden"
variants={combinedVariants}
transition={{
delay: 0.04 + delay,
duration,
ease: "easeOut",
}}
className={className}
>
{children}
</motion.div>
</AnimatePresence>
)
}
Update the import paths to match your project setup.
Examples
Hello World 👋
Nice to meet you
Props
Prop | Type | Description | Default |
---|---|---|---|
children | React.ReactNode | The content to be animated | |
className | string | The class name to be applied to the component | |
variant | object | Custom animation variants for motion component | |
duration | number | Duration (seconds) for the animation | 0.4 |
delay | number | Delay (seconds) before the animation starts | 0 |
yOffset | number | Vertical offset for the animation | 6 |
inView | boolean | Whether to trigger animation when component is in view | false |
inViewMargin | string | Margin for triggering the in-view animation | "-50px" |
blur | string | Amount of blur to apply during the animation | "6px" |