Hi wgk,
I have the impression that sometimes some menu items (for example sometimes while clicking from menu item 3 to 4) - if I understand you correctly - are the way you want them to be. I hope this can help you a little to find the hook.
Hi @wgk,
Basically you need to toggle the open class on the span with a class of menu-btn. Right now, clicking on the button itself toggles the open class, but the menu items do not. You can just modify the JavaScript that you have for making the menu show and hide. Do you want to give a try at modifying the code first?
Cheers,
Bob
Hi @wgk,
This should work for you.
First - give the span with a class of menu-btn an id of menuButton
Second - change out your menu-close.js code with:
let navItems = document.querySelectorAll('.close-item');
let navClose = document.querySelector('.navbar-collapse');
let menuButton = document.getElementById('menu-button');
navItems.forEach(item => {
item.addEventListener('click', (e) => {
if (navClose.classList.contains('show')) {
navClose.classList.remove('show');
}
if (menuButton.classList.contains('open')) {
menuButton.classList.remove('open');
}
});
});
this was definitely a big step in the right direction
Now when I select a menu item, the popup menu closes and the hamburger reappears.
But there is still one problem: If I now click on the hamburger again to select a menu item, the hamburger does not change its appearance and the change to the âXâ is not completed.
Another click and the change works again as it shouldâŚ
Do you have any idea how to fix this? That would be then as I would wish it.
Hi @wgk,
More fun with hamburgers! So, I didnât look at the code you had added to the page to open and close the menu. I thought it was a normal Bootstrap toggle. So, the reason the opening is getting out of synch is that your other JS is using a variable to keep track of whether the menu is open or not. The closing of the menu by clicking on an item doesnât change that variable, but clicking on the hamburger icon does. I would get rid of the main.js file and change it to:
let navItems = document.querySelectorAll('.close-item');
let navClose = document.querySelector('.navbar-collapse');
let menuButton = document.getElementById('menu-button');
menuButton.addEventListener('click', (e) => {
menuButton.classList.toggle('open');
});
navItems.forEach(item => {
item.addEventListener('click', (e) => {
navClose.classList.toggle('show');
menuButton.classList.toggle('open');
});
});
since Iâm not very familiar with such things (Iâm gradually teaching myself a little bit), I may not have understood it the way you meant it. Even now I had to think a bit about what to do
I have now added the new value to the line: "span class=âmenu-btnâ.
So now the line is: âspan class=âmenu-btnâ id=âmenu-buttonââ and lo and behold - it seems to finally work the way I wanted it to.
You have helped me a lot with this and I would like to thank you very much for that.
So thank you very much for the great support and also for your patience. Without your support I would never have managed it.