Auto close mobile menu after clicking link

Solved
AntonC
Excursionist
55 1 1

Hi

I am trying to get the mobile menu to auto close after clicking on a link rather then having to click on the X to close it....

current code is :

menuMobile = function() {
$('#megamenu_mobile_toggle').on('click.mobileMenu', function(){
$('#megamenu_level__1, #megamenu_mobile_close').show().addClass('on');

$('html, body').css('overflow', 'hidden');
});
$('#megamenu_mobile_close').on('click', function() {
$('#megamenu_level__1, #megamenu_mobile_close').removeClass('on');

$('html, body').css('overflow', 'auto');
});

$('.megamenu_trigger').on('click.mobileMenu', function() {
var targetMenu = '#' + $(this).data('submenu');
$(targetMenu).slideToggle(300);
$(this).toggleClass('active');
return false;
});
};

tia

0 Likes
AntonC
Excursionist
55 1 1

correct code:

  megamenuToggle = function() {
    if ( $(window).width() > 991 ) {
      $('#megamenu').removeClass('megamenu_mobile').addClass('megamenu_desktop');
      $('#megamenu_level__1').superfish();
      $('#megamenu .level_1, #megamenu .level_2, #megamenu .level_3').removeAttr('style');
      $('#megamenu_mobile_toggle, .megamenu_trigger').off('.mobileMenu').removeClass('off active');
      $('#megamenu_level__1, #megamenu_mobile_close').removeClass('on');
      $('html, body').css('overflow', 'auto');
      mobFlag = 0;
    }
    else {
      $('#megamenu_level__1, #megamenu_mobile_close').hide();
      $('#megamenu').removeClass('megamenu_desktop').addClass('megamenu_mobile');
      $('#megamenu_level__1').superfish('destroy');

      if ( mobFlag == 0 ) {
        menuMobile();
        mobFlag = 1;
      };
    };
  };

  menuMobile = function() {
    $('#megamenu_mobile_toggle').on('click.mobileMenu', function(){
      $('#megamenu_level__1, #megamenu_mobile_close').show().addClass('on');
      $('html, body').css('overflow', 'hidden');
    });

    $('#megamenu_mobile_close').on('click', function() {
      $('#megamenu_level__1, #megamenu_mobile_close').removeClass('on');
      $('html, body').css('overflow', 'auto');
    });

    $('.megamenu_trigger').on('click.mobileMenu', function() {
      var targetMenu = '#' + $(this).data('submenu');
      $(targetMenu).slideToggle(300);
      $(this).toggleClass('active');
      return false;
    });
  };
0 Likes
AntonC
Excursionist
55 1 1

This is an accepted solution.

managed to fix it by using:

$("#megamenu_level__1 li a").on("click", function() {
$('#megamenu_level__1, #megamenu_mobile_close').removeClass('on');

$('html, body').css('overflow', 'auto');
});

 

0 Likes