[feat] attempt to reduce laggy animation

This commit is contained in:
Alvalen 2023-09-21 10:32:32 +07:00
parent 87c1ec1b82
commit 2ce97cccb9

View file

@ -13,7 +13,9 @@ const NavItems = ({ isNavOpen, setIsNavOpen }) => {
open: { open: {
clipPath: `circle(1920px at calc(100% - 40px) 40px)`, clipPath: `circle(1920px at calc(100% - 40px) 40px)`,
transition: { transition: {
type: "tween", // Use a linear or ease transition type: "spring",
stiffness: 400,
damping: 40,
}, },
}, },
closed: { closed: {
@ -43,7 +45,13 @@ const NavItems = ({ isNavOpen, setIsNavOpen }) => {
// Check screen width and adjust clipPath for smaller screens // Check screen width and adjust clipPath for smaller screens
if (isMobile) { if (isMobile) {
navVariant.closed = { (navVariant.open = {
clipPath: `circle(1920px at calc(100% - 40px) 40px)`,
transition: {
type: "tween",
},
}),
(navVariant.closed = {
clipPath: "circle(0px at calc(100% - 35px) 35px)", clipPath: "circle(0px at calc(100% - 35px) 35px)",
transition: { transition: {
delay: 0.5, delay: 0.5,
@ -51,9 +59,17 @@ const NavItems = ({ isNavOpen, setIsNavOpen }) => {
stiffness: 400, stiffness: 400,
damping: 40, damping: 40,
}, },
}; });
} else { } else {
navVariant.closed = { (navVariant.open = {
clipPath: `circle(1920px at calc(100% - 40px) 40px)`,
transition: {
type: "spring",
stiffness: 400,
damping: 40,
},
}),
(navVariant.closed = {
clipPath: "circle(0px at calc(100% - 120px) 35px)", clipPath: "circle(0px at calc(100% - 120px) 35px)",
transition: { transition: {
delay: 0.5, delay: 0.5,
@ -61,7 +77,7 @@ const NavItems = ({ isNavOpen, setIsNavOpen }) => {
stiffness: 400, stiffness: 400,
damping: 40, damping: 40,
}, },
}; });
} }
const itemVariants = { const itemVariants = {
open: { open: {
@ -180,9 +196,7 @@ const Navbar = () => {
<div> <div>
<h1 <h1
className={`text-2xl ml-2 md:ml-0 ${ className={`text-2xl ml-2 md:ml-0 ${
isNavOpen isNavOpen ? "text-white" : ""
? "text-white"
: ""
}`}> }`}>
Alvalens Alvalens
</h1> </h1>