DIVI theme- Collapsible Nested Sub Menu Items for Mobile

Question:

How can we do the Collapsible Nested Sub Menu Items on Divi’s Mobile Menu ?

Solution:

Default DIVI mobile menu is shown in the image as below.

If we have to just use the below CSS and script in our site. We can put below CSS and JS script going to WP-admin ->Divi Theme Options -> Integrations -> Add code to the body .

Or In child-theme (if you are using) style and js/script file.

CSS:

#main-header .et_mobile_menu .menu-item-has-children > a { background-color: transparent; position: relative; }
#main-header .et_mobile_menu .menu-item-has-children > a:after { font-family: 'ETmodules'; text-align: center; speak: none; font-weight: normal; font-variant: normal; text-transform: none; -webkit-font-smoothing: antialiased; position: absolute; }
#main-header .et_mobile_menu .menu-item-has-children > a:after { font-size: 16px; content: '\4c'; top: 13px; right: 10px; }
#main-header .et_mobile_menu .menu-item-has-children.visible > a:after { content: '\4d'; }
#main-header .et_mobile_menu ul.sub-menu { display: none !important; visibility: hidden !important;  transition: all 1.5s ease-in-out;}
#main-header .et_mobile_menu .visible > ul.sub-menu { display: block !important; visibility: visible !important; }

Script:

(function($) {
      
    function setup_collapsible_submenus() {
        var $menu = $('#mobile_menu'),
            top_level_link = '#mobile_menu .menu-item-has-children > a';
             
        $menu.find('a').each(function() {
            $(this).off('click');
              
            if ( $(this).is(top_level_link) ) {
                $(this).attr('href', '#');
            }
              
            if ( ! $(this).siblings('.sub-menu').length ) {
                $(this).on('click', function(event) {
                    $(this).parents('.mobile_nav').trigger('click');
                });
            } else {
                $(this).on('click', function(event) {
                    event.preventDefault();
                    $(this).parent().toggleClass('visible');
                });
            }
        });
    }
      
    $(window).load(function() {
        setTimeout(function() {
            setup_collapsible_submenus();
        }, 700);
    });
 
})(jQuery);

Output:

Now, when we will refresh on the front end we should have a mobile menu that looks like the images below.

Our new collapsed mobile menu is as below.

Our new mobile menu expanded one level.

Hope this post will help you :). Feel free to give any suggestion in comment.

1 comment:

  1. Lets find out a little about topics and afterward investigate a few hints on picking your most ideal WordPress topic. Elegant Themes Divi Builder Plugin v4.0.7

    ReplyDelete