I am trying to make an accordion menu. I am comparing the height property to open and close the menu. But in the first click it doesn't work, it works well after the second, third click. To me, my algorithm made sense. But often I get results that I didn't expect.
let portfolio_button = document.getElementById('portfolio--button');
let portfolio_menu = document.getElementById('portfolio--menu');
let i = 0;
let mobile_menu = document.getElementById('mobile--menu');
let mobile_menu_icon = document.getElementById('mobile--menu--icon');
function portfolioMenu(){
if(portfolio_menu.style.height === "0px"){
portfolio_menu.style.height = "100px";
mobile_menu.style.height = "370px";
}
else{
portfolio_menu.style.height = 0;
mobile_menu.style.height = "270px";
}
}
function openMobileMenu() {
if (mobile_menu.style.height === "