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

154
Visualizações
Setting style animation with javascript not working

I am trying to create a burgermenu for mobile devices. I followed a tutorial and everything worked well until i get to the js part. Here is the js code:

const navSlide = () => {
    const burger = document.querySelector('.burger');
    const nav = document.querySelector('.nav-links');
    const navLinks = document.querySelectorAll('.nav-links li');
    
    burger.addEventListener('click', () => {
        //toggle nav
        nav.classList.toggle('nav-active');

        //Animate links
        navLinks.forEach((link, index) => {
            if(link.style.animation)
            {
                link.style.animation = '';
            }
            else
            {
                console.log(link.style.animation);
                link.style.animation = 'navLinkFade 0.5s ease forwards ${index / 7 + 0.3}s';
                console.log(link.style.animation);
            }
        });
    });


};

navSlide();

Basicly it is activating the menu to float in from the right and then each menu item should ease in. The problem is the animation for the menu items is not there. This is the line which should set this animation:

link.style.animation = 'navLinkFade 0.5s ease forwards ${index / 7 + 0.3}s';

I put the two console logs around it to see what happens and both times it is an empty string. I do not understand why this is. I am not very good at js so probably it is something really stupid. I looked at this for some time now so i would be really gradefull if someone could help me.

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

0

change link.style.animation to this:

link.style.animation = `navLinkFade 0.5s ease forwards ${index / 7 + 0.3}`;
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