I am developing a responsive menu where in the mobile version it is called through an icon, however on some occasions when we resize the page a click event stops working and the class (just below) .menu-mobile is not withdrawn
<div class="nav-toggle"></div>
<nav class="menu">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</nav>
.
function menu (){
$('.nav-toggle').click( function () {
if ($('.menu').hasClass('menu-mobile')) {
$('.menu').addClass('abrir-menu').removeClass('menu-mobile');
} else {
$('.menu').addClass('menu-mobile').removeClass('abrir-menu');
} }); }
$(window).resize( function (){
var largura = $(window).width();
if(largura < 767){
$('.menu').addClass('menu-mobile');
} else {
$('.menu').removeClass('menu-mobile abrir-menu');
}
menu(); });
In summary, the .menu-mobile class serves only as a trigger to execute the conditional open and close menu