I am using a hamburger menu which toggles class with jQuery and fades in/out a hidden menu using Javascript all in the same click function. It is working except that the icon has to be clicked twice before the menu fades in initially, not even double clicking gets it to work at the same time as the icon toggles class, after that it is fine and works as expected, just the delay on first opening page, Or is there a way to do it better with jQuery, I did try a couple of ways but couldn't get it. The code is below:
// In javascript
$( document ).ready(function() {
$(".hamburger").click(function() {
$("#primary_nav").toggleClass("is-active");
}
});
// In CSS
#primary_nav {
opacity: 0;
pointer-events: none;
transition: opacity 300ms;
}
#primary_nav.is-active {
opacity: 1;
pointer-events: auto;
}
Its all inside an init() function so Im not sure if I need the document ready. (I am using Sage 9 for Wordpress) Any tips welcome. Thanks
Update I scrapped the javascript fades to use the jQuery toggle and css as in below answer, so its like that at the moment. The original Javascript target the js-btn on click. Wordpress generates extra classes menu-main-container etc as in image below. Just need this little bit to finish the nav. Thanks