jquery to toggle sub-menu but keep sub-menu open if sub-menu page active

谁都会走 提交于 2019-11-29 15:27:32

I think you have two options.

  1. Consider using Ajax to load your pages
  2. Simulate the click event on each page.

For example:

For "Portfolio" items add this

<script type="text/javascript">
  $(document).ready(function(){
      jQuery('#menu-item-38>a').trigger('click');
  });
</script>

For "About Us":

<script type="text/javascript">
  $(document).ready(function(){
      jQuery('#menu-item-180>a').trigger('click');
  });
</script>

What about removing this line

menu_ul.filter(':visible').slideUp('normal');

It would prevent to hide the inactive menus.

Give it a try and let us know.

Create an extra class in your stylesheet

.menu ul.keepthisopen {display:block !important;}

Add the class to the ul in the submenu that you want to keep open.

(example) On the "About" page, go to into the code, find the menu, find the "About" link which is a

  • item, and below that is the submenu for that. Change it to
    <ul class="keepthisopen">
    

    Works fine here, with the same code/scripts as you are using. The submenu will slide up again too if you click another menu item.

    I'm working with plain code though (small site) so it's easy for me to manually change this for each page.

  • 易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
    该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!