Refine hero backdrop motion

This commit is contained in:
MOH
2026-03-09 07:51:31 +01:00
parent 8f87169da1
commit 583729db53
+65 -33
View File
@@ -1,50 +1,67 @@
"use client"; "use client";
import { motion } from "framer-motion"; import { motion, useReducedMotion } from "framer-motion";
type HeroMotionBackdropProps = { type HeroMotionBackdropProps = {
compact?: boolean; compact?: boolean;
}; };
export function HeroMotionBackdrop({ compact = false }: HeroMotionBackdropProps) { export function HeroMotionBackdrop({ compact = false }: HeroMotionBackdropProps) {
const reducedMotion = useReducedMotion();
return ( return (
<div className="hero-sheet pointer-events-none absolute inset-0 overflow-hidden"> <div className="hero-sheet pointer-events-none absolute inset-0 overflow-hidden">
<div className="hero-sheet-base" /> <div className="hero-sheet-base" />
<motion.div <motion.div
animate={{ initial={false}
x: compact ? [0, 18, -10, 0] : [0, 44, -24, 0], animate={
y: compact ? [0, -16, 10, 0] : [0, -34, 18, 0], reducedMotion
scale: compact ? [1, 1.03, 0.99, 1] : [1, 1.08, 0.96, 1], ? { x: 0, y: 0 }
}} : {
x: compact ? [0, 18, -10, 0] : [0, 52, -28, 0],
y: compact ? [0, -16, 10, 0] : [0, -38, 22, 0],
scale: compact ? [1, 1.03, 0.99, 1] : [1, 1.12, 0.95, 1],
}
}
transition={{ transition={{
duration: compact ? 18 : 26, duration: compact ? 18 : 20,
repeat: Number.POSITIVE_INFINITY, repeat: Number.POSITIVE_INFINITY,
ease: "easeInOut", ease: "easeInOut",
}} }}
className="hero-blob hero-blob-left" className="hero-blob hero-blob-left"
/> />
<motion.div <motion.div
animate={{ initial={false}
x: compact ? [0, -14, 8, 0] : [0, -36, 18, 0], animate={
y: compact ? [0, 10, -8, 0] : [0, 22, -14, 0], reducedMotion
scale: compact ? [1, 0.98, 1.04, 1] : [1, 0.94, 1.08, 1], ? { x: 0, y: 0 }
}} : {
x: compact ? [0, -14, 8, 0] : [0, -42, 22, 0],
y: compact ? [0, 10, -8, 0] : [0, 26, -18, 0],
scale: compact ? [1, 0.98, 1.04, 1] : [1, 0.92, 1.1, 1],
}
}
transition={{ transition={{
duration: compact ? 20 : 28, duration: compact ? 20 : 22,
repeat: Number.POSITIVE_INFINITY, repeat: Number.POSITIVE_INFINITY,
ease: "easeInOut", ease: "easeInOut",
}} }}
className="hero-blob hero-blob-right" className="hero-blob hero-blob-right"
/> />
<motion.div <motion.div
animate={{ initial={false}
x: compact ? [0, 12, -8, 0] : [0, 26, -14, 0], animate={
y: compact ? [0, -6, 8, 0] : [0, -18, 16, 0], reducedMotion
scale: compact ? [1, 1.02, 0.98, 1] : [1, 1.06, 0.97, 1], ? { x: 0, y: 0, opacity: compact ? 0.36 : 0.38 }
opacity: compact ? [0.36, 0.5, 0.4, 0.36] : [0.34, 0.54, 0.4, 0.34], : {
}} x: compact ? [0, 12, -8, 0] : [0, 32, -16, 0],
y: compact ? [0, -6, 8, 0] : [0, -20, 18, 0],
scale: compact ? [1, 1.02, 0.98, 1] : [1, 1.1, 0.96, 1],
opacity: compact ? [0.36, 0.5, 0.4, 0.36] : [0.38, 0.6, 0.44, 0.38],
}
}
transition={{ transition={{
duration: compact ? 16 : 24, duration: compact ? 16 : 18,
repeat: Number.POSITIVE_INFINITY, repeat: Number.POSITIVE_INFINITY,
ease: "easeInOut", ease: "easeInOut",
}} }}
@@ -52,12 +69,17 @@ export function HeroMotionBackdrop({ compact = false }: HeroMotionBackdropProps)
/> />
<motion.div <motion.div
animate={{ initial={false}
opacity: compact ? [0.18, 0.26, 0.2, 0.18] : [0.2, 0.3, 0.22, 0.2], animate={
scale: compact ? [1, 1.01, 1, 1] : [1, 1.02, 1, 1], reducedMotion
}} ? undefined
: {
opacity: compact ? [0.18, 0.26, 0.2, 0.18] : [0.22, 0.36, 0.24, 0.22],
scale: compact ? [1, 1.01, 1, 1] : [1, 1.04, 1, 1],
}
}
transition={{ transition={{
duration: compact ? 16 : 22, duration: compact ? 16 : 18,
repeat: Number.POSITIVE_INFINITY, repeat: Number.POSITIVE_INFINITY,
ease: "easeInOut", ease: "easeInOut",
}} }}
@@ -65,14 +87,19 @@ export function HeroMotionBackdrop({ compact = false }: HeroMotionBackdropProps)
/> />
<motion.div <motion.div
animate={{ initial={false}
animate={
reducedMotion
? { rotate: 0 }
: {
x: compact ? [0, 10, -8, 0] : [0, 18, -14, 0], x: compact ? [0, 10, -8, 0] : [0, 18, -14, 0],
y: compact ? [0, -8, 6, 0] : [0, -18, 10, 0], y: compact ? [0, -8, 6, 0] : [0, -18, 10, 0],
rotate: compact ? [0, 2, -1, 0] : [0, 4, -2, 0], rotate: compact ? [0, 2, -1, 0] : [0, 4, -2, 0],
opacity: compact ? [0.12, 0.2, 0.14, 0.12] : [0.14, 0.24, 0.16, 0.14], opacity: compact ? [0.12, 0.2, 0.14, 0.12] : [0.16, 0.28, 0.18, 0.16],
}} }
}
transition={{ transition={{
duration: compact ? 20 : 28, duration: compact ? 20 : 22,
repeat: Number.POSITIVE_INFINITY, repeat: Number.POSITIVE_INFINITY,
ease: "easeInOut", ease: "easeInOut",
}} }}
@@ -80,13 +107,18 @@ export function HeroMotionBackdrop({ compact = false }: HeroMotionBackdropProps)
/> />
<motion.div <motion.div
animate={{ initial={false}
animate={
reducedMotion
? undefined
: {
backgroundPosition: compact backgroundPosition: compact
? ["0 0, 0 0", "40px 24px, 0 0", "0 0, 0 0"] ? ["0 0, 0 0", "40px 24px, 0 0", "0 0, 0 0"]
: ["0 0, 0 0", "64px 40px, 0 0", "0 0, 0 0"], : ["0 0, 0 0", "84px 52px, 0 0", "0 0, 0 0"],
}} }
}
transition={{ transition={{
duration: compact ? 20 : 28, duration: compact ? 20 : 20,
repeat: Number.POSITIVE_INFINITY, repeat: Number.POSITIVE_INFINITY,
ease: "linear", ease: "linear",
}} }}