Clickable Dropdown Menu

In this step-by-step tutorial, you'll learn how to create a clickable dropdown menu instead of the default hover…

Tools

Code editor

Estimated time

5 min.

Adding Class Suffix

1. The class suffix clickable-dropdown should be placed in the "Class Suffix" field of the Menu plugin.

Adding CSS

2. Copy CSS code below, go to Tools ➝ Code Editor ➝ CSS and paste it.

 


@media (min-width: 1025px) {
    .clickable-dropdown .nav li.deeper:hover > .mod-menu__sub:not(.dropdown-visible), 
    .clickable-dropdown .nav li:hover > .tabs-content-wrapper:not(.dropdown-visible) {
        display: none !important;
    }
    .clickable-dropdown .dropdown-visible {
        box-sizing: border-box !important;
        display: block !important;
    }
    .clickable-dropdown .mod-menu__sub > .deeper > .mod-menu__sub.dropdown-visible {
        left: 100%;
        position: absolute;
        top: 0px !important;
    }
}

Adding JavaScript

3. Copy JavaScript code below, go to Tools ➝ Code Editor ➝ JavaScript and paste it.

 


$(document).ready(function () {
    if (window.matchMedia("(min-width: 1025px)").matches) {
        $('.clickable-dropdown .deeper.parent > a, .clickable-dropdown .deeper.parent > span').on('click focusin', function (e) {
            e.preventDefault();
            e.stopPropagation();
            const currentParent = $(this).closest('.deeper.parent');
            const currentSubmenu = currentParent.children('.mod-menu__sub, .ba-wrapper').first();
            currentParent
                .siblings('.deeper.parent')
                .children('.mod-menu__sub.dropdown-visible, .ba-wrapper.dropdown-visible')
                .removeClass('dropdown-visible');
            if (!currentSubmenu.hasClass('dropdown-visible')) {
                currentSubmenu.addClass('dropdown-visible');
            }
        });
        $(document).on('click focusin', function (e) {
            if ($(e.target).closest('.deeper.parent').length === 0) {
                $('.mod-menu__sub, .ba-wrapper').removeClass('dropdown-visible');
            }
        });
    }
});

Something is not clear? Ask a question on community forums.