I am trying to convert a pure JavaScript, CSS, and HTML animated navbar into a ReactJS component to use in a project.
The original code is written in HTML with a separate CSS styling file, and a JavaScript file which is linked to the HTML code via <script>
tag. The below is a code snippet of my JavaScript file that I am trying to convert into ReactJS:
const navSlide = () => {
const burger = document.querySelector('.burger');
const navLinks = document.querySelectorAll('.nav-links li');
burger.addEventListener('click', ()=> {
navLinks.forEach((link, index) => {
if (link.style.animation) {
link.style.animation = '';
} else {
link.style.animation = 'navLinkFade 0.5s ease forwards $(index / 7 + 1}s
}
});
}
navSlide();
The ReactJS component that I am trying to change to accommodate the above code snippet currently contains the following code:
import React, { useState } from "react";
const NavBar = () => {
const [navOpened, setNavOpened] = useState(false);
const navClassNames = navOpened ? "nav-links nav-active" : "nav-links";
return (
<div className="navbar">
<nav>
<div className="logo">
<h4>Reuben McQueen</h4>
</div>
<ul className={navClassNames}>
<li>
<a href="#">Projects</a>
</li>
<li>
{" "}
<a href="#">Experiments</a>
</li>
<li>
{" "}
<a href="#">Skills</a>
</li>
<li>
{" "}
<a href="#">Contact Me</a>
</li>
</ul>
<div className="burger" onClick={() => setNavOpened(!navOpened)}>
<div className="line1" />
<div className="line2" />
<div className="line3" />
</div>
</nav>
</div>
);
};
export default NavBar;
The CSS for .nav-links
li
is the following:
.nav-links li {
list-style: none;
}
The code should individually move in each list item after the time delay is given.