2013-08-23 48 views

回答

0

与其将整个事物更改为新的下拉菜单,您只需简单地将下拉列表absoluteposition。我还添加了当原始列表或子菜单不再徘徊时子菜单关闭的功能。 Demo Here

/* CSS */ 
li { 
    list-style:none; 
} 
ul { 
    padding:0; 
    margin:0; 
} 
#nav { 
    float: left; 
    border-top: 1px solid #999; 
    border-right: 1px solid #999; 
    border-left: 1px solid #999; 
} 
#nav li { 
    position:relative; 
} 
#nav li a { 
    width: 200px; 
    text-align:center; 
    display: block; 
    padding: 10.7px; 
    background:#ccc; 
    border-top: 1px solid #eee; 
    border-bottom: 1px solid #999; 
    border-width:0.2px; 
    text-decoration: none; 
    color: #000; 
} 
#nav li a:hover, #nav li a.active { 
    background: #999; 
    color: #fff; 
} 
#nav li ul { 
    display: none; 
    position:absolute; 
    left:221px; 
    z-index:-1; 
    top:-1px; 
} 
#nav li ul li a { 
    padding: 10px; 
    background:#C01F25; 
    opacity:0.95; 
    border-bottom: 0.1px solid red; 
} 

/* Changed jQuery */ 
$(document).ready(function() { 
    $("#nav > li > a").on('mouseenter', function (e) { 
      if ($(this).parent().has("ul")) { 
       e.preventDefault(); 
      } 
       if (!$(this).hasClass("open")) { 
        // hide any open menus and remove all other classes 
        $("#nav li ul").slideUp(350); 
        $("#nav li a").removeClass("open"); 

        // open our new menu and add the open class 
        $(this).next("ul").slideDown(350); 
        $(this).addClass("open"); 

       } 
    }); 
    $('#nav').on('mouseleave', function (e) { 
     $('.open').removeClass('open').next("ul").slideUp(350) 
    }); 
}); 

你张贴问题,你应该提供你的代码的问题,因为有时jsFiddles被删除或网站干脆崩溃

+0

没有下一次是在演示改变。这是相同的。我不想让它滑下来,而是向右滑动。 – user2708382

+0

非常感谢,但有一个问题。当菜单向右滑动并将其悬停时,它将消失..请修复此问题。当菜单滑动到它时,你会看到这个概率谢谢。 – user2708382

+0

再次更新。希望你快乐! –