如何中断 Hover 的 handlerOut
我有以下情况:
我有一个对象,我们称其为“按钮”。当您将鼠标悬停在“按钮”上时,它会使另一个对象“信息”向下滑动。当然,当你的鼠标离开Button时,Info就会向上滑动并消失。但是,Info 有一个链接,用户可能想要单击它。我可以延迟信息向上滑动,但到达信息后我无法停止它。
这是我正在使用的代码。
$("#button").hover(function(){
$("#info").slideDown("fast");
}, function(){ //the handlerOut
$("#info").delay(1000).slideUp("fast");
});
如何告诉 Button 在鼠标悬停后不要滑动信息?
I have the following situation:
I have an object, lets call it "Button". When you mouese over Button it make another object "Info" slide down. Of course, when your mouse leaves Button, Info slides up and dissapear. But, Info has a link and the user might want to click it. I can delay the Info's slide up but I can't stop it after I reach Info.
This is the code I'm using.
$("#button").hover(function(){
$("#info").slideDown("fast");
}, function(){ //the handlerOut
$("#info").delay(1000).slideUp("fast");
});
How can I tell Button not to slideUp Info after I hover it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
stop()
停止任何当前排队的动画。请注意,stop()
会停止任何当前正在运行的动画,无论其当前位于何处,因此在这种情况下,我们需要停止动画并显示该元素。(顺便说一句,在解决行为问题之前,您可能已经想使用
stop()
来防止用户将鼠标快速移入和移出按钮时出现弹跳效果):然后,获取您想要的行为,我们需要向
#info
添加一个悬停处理程序来停止当前动画,然后根据需要显示或隐藏 info 元素。由于我们已经有一个处理程序可以执行此操作,因此您只需将#info
选择器添加到悬停调用即可:这是一个 工作 jsfiddle
You can use
stop()
to stop any currently queued animation. Note thatstop()
stops any currently running animation wherever it currently is, so in this case we'll need to stop the animation and show the element.(As an aside, before solving the behaviour issue, you might already want to use
stop()
to prevent bouncing effects if the user mouses in and out of the button very quickly):Then, to get the behaviour you want, we need to add a hover handler to
#info
that stops the current animation, and then either shows or hides the info element, as appropriate. Since we've already got a handler that does that, you can just add the#info
selector to the hover call:Here's a working jsfiddle
解决这个问题的通常方法是在相关元素隐藏之前设置一个延迟,如果用户在延迟期间悬停该元素,则完全取消隐藏。
演示位于 http://jsfiddle.net/gaby/VjLM2/
The usual solution to this problem, is to set a delay before the related element hides as well, and if the user hovers that element during the delay, to cancel the hiding completely.
Demo at http://jsfiddle.net/gaby/VjLM2/
http://jsfiddle.net/
});
http://jsfiddle.net/
});