简体   繁体   English

带手风琴的导航菜单

[英]navigation menu with accordion

I am trying to replicate what tibco.co.in has done with navigation for their Products menu. 我正在尝试复制tibco.co.in在其“产品”菜单的导航中所做的事情。 I have come up with following stuff. 我想出了以下东西。

HTML: HTML:

<li class="ASSOCIATION_MENU_HANDLER">
    <a href="javascript:void(0);">Hospital Menu</a> <!-- this is always visible-->

     <div class="ASSOCIATION_MENU"> <!-- this div shows up when I mouseover the menu-->
        <ul class="sub-options">
            <li class="submenu-level-1> <!-- level1-->
                <span>
                    <a href="javascript:void();">Apollo Hospital</a>
                </span>
                <ul>
                    <li class="submenu-level-2">
         <!-- level2-->  <span><a href="#">Accident Department</a></span>     
                    </li>
                   <!----Several Departments with li.submenu-level-2 ---------->
            </li>
            <!----Several Hospitals with li.submenu-level-1 ---------->
        </ul>
    </div>
</li>

SCRIPT: 脚本:

//shut down all expanded hospitals
jQuery(".sub-options ul").slideUp();

//trigger for showing the menu
 $(".ASSOCIATION_MENU_HANDLER").hover(
    function(){$(this).find(".ASSOCIATION_MENU").slideToggle(400);},
    function(){$(this).find(".ASSOCIATION_MENU").hide();}
), function() {
    jQuery(".sub-options ul").slideUp();
};

//controll mouseover on each hospital item
$('.sub-options > li').mouseenter( function(event) {
      jQuery(".sub-options ul").stop(); //stops all the current animations
      var me = $(this).children('ul');
      var theLi;
      //remove 'active' class from other hospitals
      $('.sub-options li').not(this).each(function() {
          theLi = $(this);
          if(theLi.find("span > a").first().hasClass("active")) {
              theLi.find("span > a").first().removeClass("active");
          }
      });
      //shut down other hospitals
      $('.sub-options ul').not(me).slideUp("slow");

     //show up the current hospital's departments
      me.slideDown("slow");
     //add 'active' class to current hospitals
      $(this).find("span > a").first().addClass("active");

});

This is working properly when the mouse movement is very slow. 当鼠标移动非常慢时,这可以正常工作。 For quicker users some problems are happening- 为了更快的用户,出现了一些问题-

  1. sometimes half of the departments of a hospital are showing up, half is gone. 有时医院的一半科室出现,一半消失了。
  2. when I mouseout, all the expanded Hospitals should shut down 当我将鼠标移出时,所有扩展的医院都应关闭
  3. Also if I do too many mouse movement over the hospitals , then only the last action should be executed ie the menu should not expand and collapse for ages. 另外,如果我在医院上进行了太多的鼠标移动,则仅应执行最后一个操作,即菜单不会随着时间的推移而展开和折叠。

Any help is appreciated. 任何帮助表示赞赏。 Here is jsfiddle version of my work 这是我工作的jsfiddle版本

At first glance perhaps it's an issue with the placement of your .stop() function. 乍一看,这可能与您的.stop()函数的位置有关。

The code you've got is a little complex to go through so apologies for the lack of your styling, but I think this is close to what you want? 对于缺少样式的代码,要道歉很复杂,但是我认为这很接近您想要的吗?

http://jsfiddle.net/fJ6x8/ http://jsfiddle.net/fJ6x8/

The example I've used is taken from this post -> http://www.webdeveloper.com/forum/showthread.php?269859-DropDown-multilevel-menu-with-hover 我使用的示例摘自本文-> http://www.webdeveloper.com/forum/showthread.php?269859-DropDown-multilevel-menu-with-hover

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM