Answer the question
In order to leave comments, you need to log in
How to make the menu of the mobile version of the site close after a click?
if ($('.main-navigation .navigation-box .sub-menu').length) {
var subMenu = $('.main-navigation .sub-menu');
subMenu.parent('li').children('a').append(function() {
return '<button class="sub-nav-toggler"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>';
});
var mainNavToggler = $('.header-navigation .menu-toggler');
var subNavToggler = $('.main-navigation .sub-nav-toggler');
mainNavToggler.on('click', function() {
var Self = $(this);
var menu = Self.data('target');
$(menu).slideToggle();
$(menu).toggleClass('showen');
return false;
});
subNavToggler.on('click', function() {
var Self = $(this);
Self.parent().parent().children('.sub-menu').slideToggle();
return false;
});
Answer the question
In order to leave comments, you need to log in
SOLUTION: Helped on a freelance site. It was just necessary to add the code to the theme.js file:
$('.main-navigation ul li a').on('click', function() {
$('.main-navigation').hide();
});
if ($('.main-navigation .navigation-box .sub-menu').length) {
var subMenu = $('.main-navigation .sub-menu');
subMenu.parent('li').children('a').append(function() {
return '<button class="sub-nav-toggler"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>';
});
var mainNavToggler = $('.header-navigation .menu-toggler');
var subNavToggler = $('.main-navigation .sub-nav-toggler');
mainNavToggler.on('click', function() {
var Self = $(this);
var menu = Self.data('target');
$(menu).slideToggle();
$(menu).toggleClass('showen');
return false;
});
subNavToggler.on('click', function() {
var Self = $(this);
Self.parent().parent().children('.sub-menu').slideToggle();
return false;
});
$('.main-navigation ul li a').on('click', function() {
$('.main-navigation').hide();
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question