Blur Fade

Blur fade in and out animation. Used to smoothly fade in and out content.

Random stock image 1
Random stock image 2
Random stock image 3
Random stock image 4
Random stock image 5
Random stock image 6
Random stock image 7
Random stock image 8
Random stock image 9

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

Props

PropTypeDescriptionDefault
childrenReact.ReactNodeThe content to be animated
classNamestringThe class name to be applied to the component
variantobjectCustom animation variants for motion component
durationnumberDuration (seconds) for the animation0.4
delaynumberDelay (seconds) before the animation starts0
yOffsetnumberVertical offset for the animation6
inViewbooleanWhether to trigger animation when component is in viewfalse
inViewMarginstringMargin for triggering the in-view animation"-50px"
blurstringAmount of blur to apply during the animation"6px"