0
I have a javascript menu and my knowledge of javascript is almost null. And unfortunately this menu on mobile he is closing alone ... and as I do not have much knowledge I am suffering to solve this problem.
Here’s the mobile site and I’ll leave the code below.
Menu closing alone : http://mobt.me/ddc6
Code :
// Header Menu Mobile Nav
if (jQuery('.menu')) {
jQuery('.nav-toggler').click(function (e) {
e.preventDefault();
jQuery(this).next('.menu').addClass('open');
e.stopPropagation();
});
jQuery('.menu').on('click', function(e) {
e.stopPropagation();
});
jQuery('body').on('click', function (e) {
jQuery('.menu').removeClass('open');
});
jQuery('#closeMenu').click(function (e) {
e.preventDefault();
jQuery('.menu').removeClass('open');
});
}
After the site is fully loaded the menu did not close alone Axcse
– BrTkCa
has some script that detects if the mouse is over/leaving the menu?
– Leandro RR
Here Continue closing regardless of the time you leave loading the site... And no, as far as I know only has this on the menu for mobile
– Axcse
so... here it closes even with the cursor over the links... bizarre. but it closes only when it toggle in the class ". open"
– Leandro RR
well, I guess that’s it, your script, starts by checking the click on ". Nav-Toggler", so if it was clicked, it adds the class ". open" in the element with class
.menu
ai continues the script, understand this as a computer processing the script. the next block detects again click on ". menu", then detects a click on the "body" element that is the body of the page, if it was clicked it removes the ". open" class from the ". "menu, and I think that’s your problem. because the ". Nav-Toggler" is inside the body tag, hence the script while adding the class it then removes– Leandro RR
Did I take away the function of clicking on the body it closes the resolve menu ? Why is it working only the function that needs to click on the X to close
– Axcse
Well I gave up the function of clicking on the body and closing the menu and it stopped closing alone... thanks for helping me see the script =)
– Axcse
I’ll put as answer here and you give the check
– Leandro RR
Take a look at my answer. No need to remove anything. Taking the functionality from the click on the body is not the best output.
– Sam