profit-planet-frontend/src/app/components/animation/pageTransitionEffect.tsx
2025-10-14 18:47:01 +02:00

37 lines
851 B
TypeScript

'use client';
import { motion, AnimatePresence } from 'framer-motion';
import { usePathname } from 'next/navigation';
import React from 'react';
const PageTransitionEffect = ({ children }: { children: React.ReactNode }) => {
const pathname = usePathname();
const variants = {
hidden: { opacity: 0, x: 0, y: 20 },
enter: { opacity: 1, x: 0, y: 0 },
exit: { opacity: 0, x: 0, y: -20 },
};
return (
<AnimatePresence
mode="wait"
onExitComplete={() => window.scrollTo(0, 0)}
>
<motion.div
key={pathname}
variants={variants}
initial="hidden"
animate="enter"
exit="exit"
transition={{ type: 'tween', duration: 0.3 }}
className="w-full"
>
{children}
</motion.div>
</AnimatePresence>
);
};
export default PageTransitionEffect;