Wordpress website - Mobile menu behavior help

hoping you could help. So, Im using xtheme, and wordpress. And I have code to make my mobile menu a fixed top menu, so its always visible. I also have JavaScript to make it retract upon clicking a menu item so the menu doesn't cover the screen.

css to make it fixed:

@media (max-width: 979px) {
  .x-navbar-fixed-top {
    position: fixed!important;
  }
}

Javascript:

jQuery(document).ready(function($){
    $('.x-navbar .mobile .x-nav ').on('click touchend', function(e) {
        document.getElementsByClassName(x-btn-navbar)[0].click()
    });
});

This works to a point, however, if you go to this page: https://foresthillcentre.com/mental-health-services/

And try the menu on all of the submenu items (setup to scroll to section on same page) The menu retracts before you can click on anything, and you have to re-click the hamburger to bring up the submenus. You will see what I mean on use...

Any suggestions to fix this?

Thank you.

Topic mobile menus Wordpress

Category Web


The CSS isn't the culprit here, there is an issue with your jQuery logic. Based on the provided jQuery it looks like you're binding click events based on class names.

I would suggest binding the click event that triggers the initial navigation dropdown to the hamburger icon's ID rather than class. And then binding a separate click event that triggers the drop downs.

It also appears that both the navigation and the submenu dropdowns share the same attribute: data-x-toggleable="x-nav-wrap-mobile" this may be the cause of the issue.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.