在元素之间移动鼠标太快时的 jQuery 悬停问题
我在页面上多次重复以下 html:
<div class="outer">
outer
<div class="inner">
inner
</div>
</div>
并使用此 jQuery:
$('.inner').hide();
$('.outer').hover(function(e) {
$(this).children('.inner').show("slide", {
direction: "right"
}, 1000);
}, function(e) {
$(this).children('.inner').hide("slide", {
direction: "right"
}, 1000);
});
正如您在此处看到的: http:// /jsfiddle.net/342q3/15/ 在div之间缓慢移动鼠标(等待动画完成)可以达到一次只显示一个内部div的预期效果。
但是,如果您在 div 之间快速移动鼠标,所有内部 div 仍然可见。
我尝试过使用 stop() 函数但没有成功。 如何防止内部 div 保持打开状态?
I have the following html repeated many times on a page:
<div class="outer">
outer
<div class="inner">
inner
</div>
</div>
and have this jQuery:
$('.inner').hide();
$('.outer').hover(function(e) {
$(this).children('.inner').show("slide", {
direction: "right"
}, 1000);
}, function(e) {
$(this).children('.inner').hide("slide", {
direction: "right"
}, 1000);
});
As you can see here: http://jsfiddle.net/342q3/15/ moving the mouse slowly between the divs (waiting for the animation to complete) achieves the desired effect of displaying only one inner div at a time.
However if you move the mouse quickly between the divs, all the inner divs remain visible.
I've tried using the stop() function but without success. How can I prevent the inner divs from remaining open?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您在开始新动画(滑出)之前停止动画并使用
find
而不是children
(不知道为什么它不适用于children< /code>),它按预期工作:
http://jsfiddle.net/AVLdW/
If you stop the animation before you start the new one (sliding out) and use
find
instead ofchildren
(no idea why it doesn't work withchildren
), it works as supposed:http://jsfiddle.net/AVLdW/
尝试使用
animation()
编写代码,这样您就可以随时stop()
它并设置默认样式。try writing code with
animation()
that way you'll be able tostop()
it anytime and set default styles.Animate() 是你想要的函数,我已经使用这个 functiong 和这种语法编写了我的导航系统:
显然你不想改变你的 BG 位置,你会在那里调用你的幻灯片函数,但它是这种概念。
Animate() is the function you want, I have written my navigation system using this functiong with this kind of syntax:
Obviously you'd not want to change the BG position in yours, you'd call you slide function in there, but it's this kind of concept.