Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
Run function when framer-motion animation starts

I have a container with a mount animation and when set to beforeChildren. The child also has a mount animation.

Therefore, the mount animation of the child starts playing once the parent animation is over. However, the child component is mounted in the component tree at the same time the parent is.

This is a problem because I want to run some code exactly the moment the child's animation starts (in this case, play a sound).

Example code:

// parent.js
import { motion } from 'framer-motion';
import Child from './child';

export default function Parent() {
  const variants = {
    initial: {
      opacity: 0,
    },
    animate: {
      opacity: 1,
      transition: {
        duration: 1,
        when: 'beforeChildren'
      }
    }
  };

  return (
    <motion.div
      variants={variants}
      initial="initial"
      animate="animate"
    >
      <h1>Parent displayed!</h1>
      <Child/>
    </motion.div>
  );
}
// child.js
import { motion } from 'framer-motion';

export default function Child() {
  const variants = {
    initial: {
      opacity: 0,
    },
    animate: {
      opacity: 1,
      transition: {
        duration: 1,
      }
    }
  };

  return (
    <motion.div
      variants={variants}
    >
      <h1>Child displayed!</h1>
    </motion.div>
  );
}

Besides literally writing my own orchestration library, how do I run some code the moment the child's animation starts?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda