将鼠标悬停在父引导程序上时,会显示导航栏中的子菜单下拉列表

时间:2017-06-21 11:08:35

标签: jquery html css twitter-bootstrap navbar

嗨朋友们正在尝试显示子菜单下拉菜单,只有当其父项悬停时才会显示,但是当它的祖父母自动悬停时它会显示。这是代码..

 <nav class="navbar navbar-default">
     <div class="container">
         <ul class="nav navbar-nav">
             <li class="dropdown">
              <a class="dropdown-toggle disabled" data-toggle="dropdown" href="https://www.drona.in/current-affairs/">GOVT JOBS</a>
        <li class="dropdown-submenu">
    <a class="test" data-toggle="dropdown" tabindex="-1" href="#">New               
       dropdown <span class="caret"></span></a>
    <ul class="dropdown-menu">
      <li><a tabindex="-1" href="#">2nd level dropdown</a></li>
      <li><a tabindex="-1" href="#">2nd level dropdown</a></li>
                       </ul>
                  </li>
          </ul>
       </div>
    </nav>

这是js

 $(function(){
$(".dropdown").hover(            
        function() {
            $('.dropdown-menu', this).stop( true, true ).fadeIn("fast");
            $(this).toggleClass('open');
            $('b', this).toggleClass("caret caret-up");                
        },
        function() {
            $('.dropdown-menu', this).stop( true, true ).fadeOut("fast");
            $(this).toggleClass('open');
            $('b', this).toggleClass("caret caret-up");                
        });

实际上,当我将鼠标悬停在新的下拉列表上时,应该会打开2级下拉列表,但是当它处于政府工作岗位时会打开

1 个答案:

答案 0 :(得分:0)

如果您愿意,只能使用CSS。

Html标记:

<div class="dropdown">
        <a id="dLabel" role="button" data-toggle="dropdown" class="btn btn-primary" data-target="#" href="/page.html">
            Dropdown <span class="caret"></span>
        </a>
        <ul class="dropdown-menu multi-level" role="menu" aria-labelledby="dropdownMenu">
          <li><a href="#">Some action</a></li>
          <li><a href="#">Some other action</a></li>
          <li class="divider"></li>
          <li class="dropdown-submenu">
            <a tabindex="-1" href="#">Hover me for more options</a>
            <ul class="dropdown-menu">
              <li><a tabindex="-1" href="#">Second level</a></li>
              <li class="dropdown-submenu">
                <a href="#">Even More..</a>
                <ul class="dropdown-menu">
                    <li><a href="#">3rd level</a></li>
                    <li><a href="#">3rd level</a></li>
                </ul>
              </li>
              <li><a href="#">Second level</a></li>
              <li><a href="#">Second level</a></li>
            </ul>
          </li>
        </ul>
    </div>

和CSS

.dropdown-submenu {
    position: relative;
}

.dropdown-submenu>.dropdown-menu {
    top: 0;
    left: 100%;
    margin-top: -6px;
    margin-left: -1px;
    -webkit-border-radius: 0 6px 6px 6px;
    -moz-border-radius: 0 6px 6px;
    border-radius: 0 6px 6px 6px;
}

.dropdown-submenu:hover>.dropdown-menu {
    display: block;
}

.dropdown-submenu>a:after {
    display: block;
    content: " ";
    float: right;
    width: 0;
    height: 0;
    border-color: transparent;
    border-style: solid;
    border-width: 5px 0 5px 5px;
    border-left-color: #ccc;
    margin-top: 5px;
    margin-right: -10px;
}

.dropdown-submenu:hover>a:after {
    border-left-color: #fff;
}

.dropdown-submenu.pull-left {
    float: none;
}

.dropdown-submenu.pull-left>.dropdown-menu {
    left: -100%;
    margin-left: 10px;
    -webkit-border-radius: 6px 0 6px 6px;
    -moz-border-radius: 6px 0 6px 6px;
    border-radius: 6px 0 6px 6px;
}