- This topic has 8 replies, 4 voices, and was last updated 9 years, 1 month ago by
Tom.
-
AuthorPosts
-
September 23, 2016 at 3:48 pm #228987
Alex
I’m working with a single-page site that uses section id’s for the nav menu links. When viewing on a mobile screen, the mobile menu stays open after clicking a link. I would like to have the mobile menu automatically collapse when a menu item is clicked. Is there a theme option for this that I am missing, or will this need to be accomplished by adding a jquery script?
September 23, 2016 at 11:19 pm #229015Tom
Lead DeveloperLead DeveloperHi Alex,
This code might help: https://gist.github.com/generatepress/6e122667d28cabd23582
Let me know 🙂
September 24, 2016 at 1:56 am #229038Alex
Hi Tom,
Yes, works perfectly! thank you 🙂
September 24, 2016 at 7:53 am #229094Tom
Lead DeveloperLead DeveloperYou’re welcome 🙂
March 10, 2017 at 1:33 am #289625Steve
Hello – i tried to strip the jquery off the smooth scroll ability since iam using “page scroll 2 id”.
It is working like intended but I never used jquerys before so would you mind taking a look? (i fear that i added bugs or take infinite ram or something bad)<script> jQuery( document ).ready( function( $ ) { $( document ).on( 'click', '.main-nav li > a:first-child', function( e ) { var mobile = $( '.menu-toggle' ); if ( mobile.is( ':visible' ) ) { $( '.menu-toggle').closest( '.main-navigation' ).removeClass( 'toggled' ); $( '.menu-toggle').closest( '.main-navigation' ).attr( 'aria-expanded', $( '.menu-toggle').closest( '.main-navigation' ).attr( 'aria-expanded' ) === 'true' ? 'false' : 'true' ); $( '.menu-toggle').removeClass( 'toggled' ); $( '.menu-toggle').children( 'i' ).addClass( 'fa-bars' ).removeClass( 'fa-close' ); $( '.menu-toggle').attr( 'aria-expanded', $( this ).attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' ); } }); }); </script>March 10, 2017 at 6:28 am #289723Leo
StaffCustomer SupportHi Steve,
Looks like the same block of code as Tom provided here: https://generatepress.com/forums/topic/responsive-menu-and-anchor-links/#post-273558 so it should be good!
March 10, 2017 at 6:31 am #289725Steve
Oh i didnt found that.
Thank you very much.March 10, 2017 at 6:33 am #289728Leo
StaffCustomer SupportYou’re welcome 🙂
March 10, 2017 at 9:49 am #289806Tom
Lead DeveloperLead DeveloperThe next version of GP does this for you automatically, so you’ll be able to remove that JS.
-
AuthorPosts
- You must be logged in to reply to this topic.