Skip to main content
Skip to article

Better Mobile menu codes

1,241 views
document.addEventListener('DOMContentLoaded', () => {

    //replace the id #bmm with the id of your container, 
    //do this to avoid this code applying to other nav items on your page

    const menuItemLinks = document.querySelectorAll('#bmm .bricks-mobile-menu-wrapper .menu-item a');
    const menuToggle = document.querySelector('#bmm .bricks-mobile-menu-toggle');

    const handleClick = () => {
        if (menuToggle) {
            menuToggle.click();
        }
    };

    if (window.matchMedia('(max-width:768px)').matches) {
        menuItemLinks.forEach(link => {
            link.addEventListener('click', (event) => {                
                handleClick();
            });
        });
    }
});
@media (max-width:768px){
    
#bmm .bricks-mobile-menu-wrapper {
margin-top: var(--header-height);
padding-bottom: var(--header-height)
    
}

#bmm ul,
#bmm ul a{
    
    width: 100%
}

#bmm .bricks-mobile-menu-toggle{
    margin-bottom: 10px;
}


#bmm .bricks-mobile-menu-overlay{
    display: none;
}

}
Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how Design with Cracka is funded, why it matters, and how you can support us.
Join the Community
Join over 7000 learners and contributors on Design with Cracka community. Don't miss out on the conversations!
dicecartselectearthcrossarrow-rightlayerstext-align-center