I'm currently working on a menu overlay that expands to fill the screen when a user clicks a button in the corner. I'd like the menu items to fade in one by one, similar to the effect used on this website:
Most of the functionality is there, but I'm facing an issue where the menu items only fade in smoothly the first time the button is clicked. After that, they just appear suddenly (except for the first item). Can anyone help me figure out how to fix this?
You can view my code on CodePen.
Here's the HTML snippet:
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div id="menu"></div>
<div id="menu-button"></div>
<div id="menu-container">
<div id="links">
<a href="#Portfolio" id="portfolio">Portfolio</a><br />
<a href="#Services" id="services">Services</a><br />
<a href="#About" id="about">About</a><br />
<a href="#Contact" id="contact">Contact</a><br />
</div>
</div>
My CSS styling:
#menu {
position: absolute;
top: 0;
left: 0;
width: 100px;
height: 100px;
z-index: 1;
background-color: #111;
-webkit-transition: width 0.5s, height 0.5s;
transition: width 0.5s, height 0.5s;
}
#menu.active {
width: 100%;
height: 100%;
}
...
Javascript function:
let menu = {
div: document.getElementById('menu'),
button: document.getElementById('menu-button'),
container: document.getElementById('menu-container'),
isExpanded: false,
adjust: function() {
menu.isExpanded = !menu.isExpanded;
if (menu.isExpanded) {
menu.div.classList.add("active");
menu.button.classList.add("active");
menu.container.classList.add("active");
} else {
menu.div.classList.remove("active");
menu.button.classList.remove("active");
menu.container.classList.remove("active");
}
}
}
let links = document.getElementById('links').childNodes;
...
Note: Initially, I omitted mentioning that my original HTML uses Bootstrap's reset CSS. I have since added a link to a Bootstrap CDN.