如何解决这个恼人的jQuery鼠标悬停问题
How to solve this annoying jQuery mouse hover issue?
我试图做一些应该是非常简单的,但它导致这个奇怪的问题。基本上我在一个页面上有一堆相同的div,每个div都有一个嵌套的div和段落内容在那个嵌套的div中。嵌套的div和它的所有内容最初都是使用css隐藏的。当用户将鼠标悬停在主div上时,嵌套的div和它的所有内容都会消失在视图中。
到目前为止,它工作得很好…
现在,当用户的鼠标离开div时,嵌套的div再次被隐藏。问题是,当你将鼠标垂直移动到各种div上快速来回时嵌套的div在某些情况下不再消失,但仍在视图中。如何解决这个问题?
这里是一个例子,我试图达到的效果,不复制他们的代码:)
http://www.crackpixels.com/
这是我的代码,你可以按原样运行,所有东西都是绝对链接的:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
// when user hovers over box
$('.box').mouseover(function() {
$(this).children('div').fadeIn('fast');
});
// when user's mouse leaves box
$('.box').mouseleave(function() {
$(this).children('div').hide();
});
});
</script>
<style>
.box {
padding: 5px;
float: left;
margin-bottom: 20px;
border: 1px solid #ccc;
background: #F5F5F5;
margin: 0 10px 0;
}
.box div {
display: none; /* hide initially */
position: absolute;
width: 288px;
height: 175px;
margin: -175px 0 0;
background: #444;
color: #fff;
}
</style>
<div class="box">
<img src="http://www.google.com/images/logos/ps_logo2.png" height="175" width="288" />
<div>
<p>
Hello world foo bar foo<br />
Hello world foo bar foo<br />
Hello world foo bar foo<br />
Hello world foo bar foo<br />
Hello world foo bar foo<br />
Hello world foo bar foo
</p>
</div>
</div><!-- box -->
<div class="box">
<img src="http://www.google.com/images/logos/ps_logo2.png" height="175" width="288" />
<div>
<p>
Hello world foo bar foo<br />
Hello world foo bar foo<br />
Hello world foo bar foo<br />
Hello world foo bar foo<br />
Hello world foo bar foo<br />
Hello world foo bar foo
</p>
</div>
</div><!-- box -->
<div class="box">
<img src="http://www.google.com/images/logos/ps_logo2.png" height="175" width="288" />
<div>
<p>
Hello world foo bar foo<br />
Hello world foo bar foo<br />
Hello world foo bar foo<br />
Hello world foo bar foo<br />
Hello world foo bar foo<br />
Hello world foo bar foo
</p>
</div>
</div><!-- box -->
<div class="box">
<img src="http://www.google.com/images/logos/ps_logo2.png" height="175" width="288" />
<div>
<p>
Hello world foo bar foo<br />
Hello world foo bar foo<br />
Hello world foo bar foo<br />
Hello world foo bar foo<br />
Hello world foo bar foo<br />
Hello world foo bar foo
</p>
</div>
</div><!-- box -->
<div class="box">
<img src="http://www.google.com/images/logos/ps_logo2.png" height="175" width="288" />
<div>
<p>
Hello world foo bar foo<br />
Hello world foo bar foo<br />
Hello world foo bar foo<br />
Hello world foo bar foo<br />
Hello world foo bar foo<br />
Hello world foo bar foo
</p>
</div>
</div><!-- box -->
用mouseenter
代替mouseover
我猜这可能是因为$(this).children('div').fadeIn('fast');
过渡仍在运行?
尝试做一个$(this).children('div').stop().fadeIn();
!
尝试将mouseover()替换为mouseenter()
此外,你可能想看看hoverIntent插件:
http://cherne.net/brian/resources/jquery.hoverIntent.html…,这有助于防止错误触发,当人们鼠标移到和移出非常快。
相关文章:
- jquery鼠标选择无法正常工作
- jQuery鼠标输出调用CSS3动画
- jQuery鼠标悬停渐变效果
- Javascript/jQuery-鼠标事件没有在html上触发,添加了动态
- 我想要一个类似于网站 https://onlycoin.com/ 的jQuery鼠标滚动动画效果
- 正在尝试将jquery鼠标滚轮插件插入到jquery循环2中
- Jquery鼠标滚轮与触控板水平滚动
- 如果鼠标悬停得很快,Jquery鼠标移动会错过一些单元格
- jQuery-鼠标输入闪烁图像
- 带有setInterval的JQuery鼠标
- 如何清除jQuery鼠标悬停#id上的setTimeout
- jQuery鼠标滚动到下一个id
- Jquery鼠标悬停在子项上触发
- JQuery 鼠标悬停/淡出与淡入淡出影响单击与淡出
- 使用 jquery 鼠标滚轮
- Jquery 鼠标悬停和鼠标离开
- jQuery - 鼠标移动移动移动
- jQuery 鼠标滚轮插件缩放问题
- jQuery 鼠标事件不会触发
- 使用 jQuery 鼠标悬停时的 Svg 颜色过渡