Forum Discussion
Closing the side menu if open using a JavaScript trigger
Is there a way to verify if the menu is open, close it using JavaScript and if it's closed, do nothing?
At the moment I can only toggle it using this JavaScript.
document.querySelector("#hamburger > div").click();
- Jürgen_Schoene_Community Member
you can check if menu is closed with
document.body.classList.contains("sidebar-closed")
- MikeImageCommunity Member
Thank you.
- MikeImageCommunity Member
This code is not working for some reason.
var modernPlayerMenu = document.querySelector("#hamburger > div");
var isMenuOpen = document.body.classList.contains("sidebar-open");if (isMenuOpen) {
// The menu is open, so close it
if (modernPlayerMenu) {
modernPlayerMenu.click();
}
} else {
// The menu is already closed, do nothing
}- Jürgen_Schoene_Community Member
try not "closed":
var isMenuOpen = ! document.body.classList.contains("sidebar-closed");
https://360.articulate.com/review/content/d1391023-8e8f-494b-ab82-c014b505f9df/review
- MikeImageCommunity Member
You are the king.!! This is exactly what I was trying to build.
- WaltHamiltonSuper Hero
Just out of personal curiosity, if the menu is closed, does it hurt anything to close it? If not, why check? Just close it, and it's closed whether it was open or not.
- MikeImageCommunity Member
Trying to close the menu automatically on timeline start if it's open, then hide the hamburger menu so it not possible to open again until I decide to show it back again using JavaScript.
- WaltHamiltonSuper Hero
So maybe I wasn't clear. I don't ask why you want to close it; I'm asking why you need to check if it's open. Close it when you start the timeline. If it's already closed, it doesn't change if you close it. Seems to me to be less work, and fewer moving parts. On the other hand, look at what you learned by trying it that way. Maybe it was worth it. :)
- MikeImageCommunity Member
Do you know if it's possible to Disable the hamburger menu after hiding it using JavaScript? The "TAB" key can still open the menu even if it's not accessible via the mouse.
- Jürgen_Schoene_Community Member
you can remove the hamburger button from the tab-key sequence with
document.getElementById("hamburger").tabIndex = -1;
and reactivate the old state with
document.getElementById("hamburger").tabIndex = 0;
if you want, you can also deactivate the hamburger menu (without hiding)
document.getElementById("hamburger").style.pointerEvents = "none";
and reactivate with
document.getElementById("hamburger").style.pointerEvents = "";
- MikeImageCommunity Member
Your right, I don't need to check if it's open. I still had the toggle trigger still in mind so I had to check if it was open to trigger the toggle code.
var modernPlayerMenu = document.querySelector("#hamburger > div");
var isMenuOpen = ! document.body.classList.contains("sidebar-closed");
if (isMenuOpen) {
modernPlayerMenu.click();
} - WaltHamiltonSuper Hero
Ah, that makes sense. Thanks.
No, I can’t help with the hamburger menu. Sorry.
- MikeImageCommunity Member
what would be he variable to change if I were to use the Top bar menu?
- MichelToyos-c2cCommunity Member
Is it possible open the notes with a javascript action?