Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

143
Vistas
react framer motion animate only when button is pressed

I have a dropdown menu and when it is toggled, the menu fades in and out. The thing I am trying to remove is the closing animation being activated when the initial page is loaded. I dont want the closed animation to play when the page is initially loaded.

  const [menuOpen, setMenu] = useState(false);

  const location = useLocation();

  useEffect(() => {
    setMenu(false);
  }, [location]);

  const variants = {
    open: { opacity: 1, x: 0 },
    closed: { opacity: 0, x: "-25%" },
  };

  return (
    <div>
      <button
        onClick={() => {
          setMenu((menuOpen) => !menuOpen);
        }}
      >
      </button>
      <div>
        <motion.nav animate={menuOpen ? "open" : "closed"} variants={variants}>
          <DropDownMenu />
        </motion.nav>
      </div>
    </div>
  );

Are there any solutions so that the animations only activate when the button is toggled?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Following the docs

Set to false to initialise with the values in animate (disabling the mount animation).

// As false (disable mount animation)
<motion.div initial={false} animate={{ opacity: 0 }} />

So pass initial={false} to your motion.nav tag.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda