2

我有以下 jQuery 代码

$("#dropdown").hover(function() { 
        $(this).stop(true,true).fadeTo('fast',1);
        $("#options").stop(true,true).slideDown();
    }, function() { 
        $(this).delay(1000).stop(true,true).fadeTo('fast',0.1);
        $("#options").delay(1000).stop(true,true).slideUp();
    }
);

我期望发生的是当鼠标离开时#dropdown它会等待 1 秒钟然后继续。这没有发生。

如果有更好的方法,我想要实现的是在移动鼠标后让下拉菜单可见一两秒钟,我还想防止事件再次发生以防止伪影和“有趣” " 如果您要快速将鼠标从 div 上移出和移出

4

3 回答 3

1

您的调用stop不会放在动画队列中 - 它们会立即运行。我不确定您在“悬停”例程中是否真的需要它们。

编辑删除愚蠢

于 2010-05-19T14:47:33.783 回答
1

The problem is .stop(). If you take that out it works:

http://jsfiddle.net/LZ8yt/

于 2010-05-19T14:50:50.207 回答
0

您可以随时使用 setTimeout 进行低调。

var dropDownElement = $(this);
setTimeout(function()
{
    dropDownElement.fadeTo('fast', 0.1);
    // Other Code
}, 1000);
于 2010-05-19T14:44:54.860 回答