-
AuthorPosts
-
September 24, 2014 at 4:29 am #111275
When I click on the menu from a mobile device, the main menu expands; but all the submenus are expanded by default as well. I am planning to add 20-25 sub menus, and I do not want them all expanded when I click on the main menu. Because it will cause my entire mobile screen to be covered with submenus.
How do I fix this?
September 24, 2014 at 7:33 am #111377Hi There,
Thanks for writing in!
To assist you with this issue, we’ll first need you to provide us with your URL as stated on the forum entrance page. This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.
September 24, 2014 at 10:25 am #111519This reply has been marked as private.September 24, 2014 at 11:00 am #111549Could you try this by adding at your customizer’s custom javascript?
var menu_breakpoint = 979; jQuery(function($){ $('.s-mobile-collapse > a').click(function(e){ var current_width = $(window).width(); if(current_width > menu_breakpoint) return true; else { e.preventDefault(); $('ul.sub-menu', $(this).parent() ).each(function(){ if( $(this).hasClass('mobile-collapsed') ) $(this).removeClass('mobile-collapsed'); else $(this).addClass('mobile-collapsed'); }); } }); $(window).resize(function(){ toggle_mobile_menu_visibility($); }); toggle_mobile_menu_visibility($); }); function toggle_mobile_menu_visibility($) { var current_width = $(window).width(); if (current_width > menu_breakpoint) { $('.s-mobile-collapse > ul.sub-menu').removeClass('mobile-collapsed'); $('#menu-main').addClass('sf-menu'); } else { $('.s-mobile-collapse > ul.sub-menu').addClass('mobile-collapsed'); $('#menu-main').removeClass('sf-menu'); } }
Then add this css at your customizer’s custom css.
.sf-menu ul.mobile-collapsed { display: none !important; visibility: hidden !important; }
Then add s-mobile-collapse to each of your parent menu’s class for all level.
September 25, 2014 at 11:48 pm #112876This reply has been marked as private.September 26, 2014 at 6:13 am #113015Hi Louise,
Thanks for the login details.
Can you try the code below.
You can add this under Custom > CSS in the Customizer.
@media (max-width: 979px){ ul.sub-menu { display:none !important; visibility:hidden !important; } }
Best Regards
September 28, 2014 at 8:23 pm #114339Thanks, that worked to some extent – it collapses the mobile menu to parent items only but it doesn’t allow the parent items to expand on mobile.
September 29, 2014 at 3:48 am #114530Hi Louise,
Sorry about that.
Please add the code below.
@media (max-width: 979px){ ul.sub-menu.mobile-collapsed { display:block !important; visibility:visible !important; } }
Best Regards
September 29, 2014 at 6:20 pm #115156Below is my css – adding the above code made the whole menu expand again on mobile view:
*/Collapse menu on mobile*/ .sf-menu ul.mobile-collapsed { display: none !important; visibility: none !important; } @media (max-width: 979px){ ul.sub-menu { display:none !important; visibility:hidden !important; } } @media (max-width: 979px){ ul.sub-menu.mobile-collapsed { display:block !important; visibility:visible !important; } }
I’ve played around with different configurations, but I can’t seem to make it work.
Cheers,
LouiseSeptember 30, 2014 at 3:26 am #115352Hi Louise,
Sorry it should be the other way around.
@media (max-width: 979px){ ul.sub-menu { display:block !important; visibility:visible !important; } } @media (max-width: 979px){ ul.sub-menu.mobile-collapsed { display:none !important; visibility:hidden !important; } }
I fix it for you, please check on your end.
Thanks
September 30, 2014 at 4:48 am #115388Perfect! All good – excellent service, as always.
September 30, 2014 at 6:58 am #115460Glad we were able to help.
Have a nice day.
September 30, 2014 at 8:08 am #115536Hi
I would like to do the same thing and i’ve tried to follow what you said but it didn’t work for me. I’m not sure to have done it properly. Can you sum up everything please ?
Thank you so much for your support !
Delphine
September 30, 2014 at 9:00 am #115579Hi Delphine,
Thanks for writing in! Can you provide us with your site url to ensure that we can provide you with a tailored answer to your situation.
Thanks
September 30, 2014 at 9:02 am #115582Update: Although the parent items now expand only when clicked, the submenus display only briefly and then flick off again. I had this problem before with the whole menu and thought it was fixed. Can you please have another look?
Thanks,
Louise -
AuthorPosts