jQuery-将.one()与悬停一起使用 [英] jQuery - Using .one() with hover
问题描述
有什么办法让悬停函数只执行一次?这是我目前正在尝试的方法:
Is there any way to get a hover function to only execute once? This is what I'm currently trying:
$('#ask').live('hover', function() {
$('#homesearch-after').hide(300);
$.doTimeout( 300, function() {
hideClosedSearchLink();
showHomeSearch();
});
});
但这不起作用.我如何才能仅使该悬停激活一次?
But that's not working. How can I only get this hover to activate once?
我尝试用.one和.bind更改.live ...导致虚无.
I've tried changing .live with .one and .bind... resulting in nothingness.
推荐答案
您已经回答了问题,请使用.one()
(而不是.live()
).
You've already answered yourself, use .one()
(not .live()
).
但是正如lasseespeholt在评论中指出的那样,.hover()
是绑定到mouseenter
和mouseleave
的简写,并且本身不是事件.
But as lasseespeholt just pointed out in a comment, .hover()
is shorthand for binding to mouseenter
and mouseleave
, and is not an event in itself.
尝试一下:
$('#ask').one('mouseenter', function() {
$('#homesearch-after').hide(300);
$.doTimeout( 300, function() {
hideClosedSearchLink();
showHomeSearch();
});
});
如果仍然不起作用,请尝试仅使用优质的.hover()
,然后在完成后立即.unbind()
对其进行处理.
If that still doesn't work, try just using the good ol' .hover()
and then .unbind()
ing it immediately after it's finished.
$('#ask').hover(function() {
$('#homesearch-after').hide(300);
$.doTimeout( 300, function() {
hideClosedSearchLink();
showHomeSearch();
});
// Again taking into account what lasseespeholt said
$(this).unbind('mouseenter mouseleave')
});
这篇关于jQuery-将.one()与悬停一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!