简体   繁体   English

下拉菜单在进入链接之前消失了

[英]Drop down menu disappearing before I get to the links

Take a look at the tour link in the menu on this page . 看一下此页面菜单中的游览链接。 When I hover over tour, it's supposed to show the menu and let me choose which of the sub menus I wish to click on but it's disappearing too fast. 当我将鼠标悬停在巡视上时,它应该显示菜单并让我选择要单击的子菜单,但是它消失得太快了。

Here's the code of the menu: 这是菜单的代码:

$('.menu > li > a').filter(function(){
    if( $(this).siblings('ul').length ){ return true; }
}).hover(function(){ 
    $(this).siblings('ul').fadeIn(150); },function(){ 
    $(this).siblings('ul').fadeOut(150); }
);



Anyone know why this is happening? 有人知道为什么会这样吗?

It seems as easy as this: 看起来像这样简单:

$('.menu > li').hover(
    function(){ 
        $(this).find('ul').fadeIn(150);
    },
    function(){
        $(this).find('ul').fadeOut(150);
    }
);

Or, for the retarded boss: 或者,对于智障老板:

$('.menu > li > a').mouseenter(function(){ $(this).siblings('ul').fadeIn(150); });
$('.menu > li').mouseleave(function(){ $(this).children('ul').fadeOut(150); });

150 milliseconds is a quite short timeframe. 150毫秒是很短的时间范围。 Use a longer timeframe instead. 请改用更长的时间范围。

.hover(function(){ 
    $(this).siblings('ul').fadeIn(1500); },function(){ 
    $(this).siblings('ul').fadeOut(1500); }
);

You may also want to keep it faded in while hovering on the sub menu... You need to change you selectors (reference the whole listitems instead of the link only). 您可能还希望在将鼠标悬停在子菜单上时保持其淡入淡出状态。您需要更改选择器(仅引用整个列表项,而不是仅引用链接)。

Sample 样品
http://jsfiddle.net/E4EjZ/ http://jsfiddle.net/E4EjZ/

// INIT
$('.menu > li > ul').hide();

$('.menu > li').hover(function(){
    $(this).find('ul').fadeIn(1500); },function(){
    $(this).find('ul').fadeOut(1500); }
);

Try 尝试

$('.menu > li > a').filter(function(){
    if( $(this).siblings('ul').length ){ return true; }
}).mouseenter(function(){ 
    $(this).siblings('ul').fadeIn(150); }
).mouseleave(function(){ 
    $(this).siblings('ul').fadeOut(150); })

Instead of using onhover, you could try fading in on mouse over and fading out on mouse out. 除了尝试使用悬停外,您还可以尝试在鼠标悬停时淡入并在鼠标悬停时淡出。 That might work better for your situation and give you more control over each separate event. 这可能会更好地适合您的情况,并让您更好地控制每个单独的事件。 Check out the example posted here . 查看此处发布的示例。

If you keep your mouse pointer over the 'tour' link you'll see that it doesn't fade away. 如果将鼠标指针停留在“游览”链接上,您会发现它不会消失。 But when you move your mouse away from the a element it fades away, like it's supposed to. 但是,当您将鼠标从a元素移开时,它会像预期的那样逐渐消失。

If you use hover with the parent li element instead, it'll work for the whole container which includes both the 'tour' link and the sub menu you're fading in. 如果您将悬停与父li元素一起使用,则它将对整个容器都有效,该容器既包含“ tour”链接,也包含您正在淡入的子菜单。

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

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