Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!