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

339
Visualizações
How to play a CSS animation on every page transition with Next.js?

I'm using Next.js to generate a static website. I have created a CSS animation that plays in full screen when a specific div is created. I put the div in my _app.tsx, so that during most of the page transitions the animation can be played, because many of the HTML elements, including the div, gets destroyed and created during these transitions. However, it won't play when you move from a page to one with almost the same HTML structure (such as blog articles), probably because the div doesn't get destroyed and recreated. Is there a way to play a CSS animation on every page transition? For example, can I detect page transition and remove/regenerate the div when it won't be removed/regenerated?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I figured it out by myself after thinking about it for a while.

.animation[animate="0"] {
    animation: none;
}
.animation[animate="1"] {
    animation: /* ... */;
}

then

import Router from "next/router"
export const Animations = () => {
    const [i,setI] = useState(1)
    Router.events.on('routeChangeComplete', () => setI(1))
    Router.events.on('routeChangeStart', () => setI(0))
    return (
        <div className="animation" animate={i}></div>
    )
}
about 4 years ago · Juan Pablo Isaza Relatório
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