Mobile Menu Opens and Closes by Itself
-
Hi @kharisblank
Thank you very much for the last code:
But I didn’t pay attention that it has some bug: before to start scrolling or after scrolling all the way back to top, if you click on the mobile menu it opens and close by itself right away…
Could you please look into the code again, please.Many thanks!
jQuery(function($) { if ( matchMedia( 'only screen and (max-width: 1024px)' ).matches ) { var headerFix = $('.site-header').offset().top; var vDistance = headerFix+280; var inserated = false $(window).on('load scroll', function() { var y = $(this).scrollTop(); if ( y >= vDistance) { if(inserated == false){ var newHead = $('#masthead').clone(); (newHead).prependTo('body').addClass('masthead-clone').animate({ top: 0 }).resize(); $('.btn-menu').on('click', function(e) { $('#mainnav-mobi').slideToggle(300); $(this).toggleClass('active'); e.stopImmediatePropagation() }); $(document).on('click', '#mainnav-mobi li .btn-submenu', function(e) { $(this).toggleClass('active').next('ul').slideToggle(300); e.stopImmediatePropagation() }); inserated = true; } } else { $('.masthead-clone').animate({ top: -200 }).remove(); inserated = false; } }); } });
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Mobile Menu Opens and Closes by Itself’ is closed to new replies.