如何告诉.hover()等待? [英] How to tell .hover() to wait?
问题描述
我有一个下拉菜单。现在,当它滑落到多个级别时,我希望它在等待2秒钟之前等待时间消失,因此用户可以在中断 .hover()
是否有可能?
我的幻灯片代码:
/ p> $('。icon')。hover(function(){
$('li.icon> ul ').slideDown('fast');
},function(){
$('li.icon> ul')。slideUp('fast');
});
这将使第二个函数等待2秒毫秒):
$ p $ $('。icon')。hover(function(){
clearTimeout($ (this).data('timeout'));
$('li.icon> ul')。slideDown('fast');
},function(){
var ('fast');
},2000);
$(this).data ('timeout',t);
});
它还会清除用户为避免疯狂行为而暂停的超时。
然而,这并不是一个非常优雅的方式。您应该查看 hoverIntent 插件,该插件旨在解决此特定问题。
I have a drop down menu. Now when it's slided down to multiple levels, I'd like it to add wait time for like 2 secs, before it disappears, so the user can get back in, when he breaks the .hover()
by mistake.
Is it possible?
my code for the slide:
$('.icon').hover(function() {
$('li.icon > ul').slideDown('fast');
}, function() {
$('li.icon > ul').slideUp('fast');
});
This will make the second function wait 2 seconds (2000 milliseconds) before executing:
$('.icon').hover(function() {
clearTimeout($(this).data('timeout'));
$('li.icon > ul').slideDown('fast');
}, function() {
var t = setTimeout(function() {
$('li.icon > ul').slideUp('fast');
}, 2000);
$(this).data('timeout', t);
});
It also clears the timeout when the user hovers back in to avoid crazy behavior.
This is not a very elegant way of doing this, however. You should probably check out the hoverIntent plugin, which is designed to solve this particular problem.
这篇关于如何告诉.hover()等待?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!