[英]Hide div on mouseout of one of two divs, but not in between
I currently have two <div>
s. 我目前有两个
<div>
。 When hovering the first, the second should fade in. When mouseout
ing the first or the second, the second should fade out again. 将
mouseout
悬停在第一个上时,第二个应淡入。将mouseout
悬停在第一个或第二个上时,第二个应再次淡出。 However, when moving the mouse from the first to the second, the second should stay (like a mouseover-menu). 但是,将鼠标从第一个移到第二个时,第二个应保持不变(就像鼠标悬停菜单一样)。
What I've implemented now are simple mouseover
/ mouseout
event handlers: http://jsfiddle.net/tC3ZL/2/ . 我现在实现的是简单的
mouseover
/ mouseout
事件处理程序: http : //jsfiddle.net/tC3ZL/2/ 。
$('#div1').mouseover(function() {
$('#div2').fadeIn(500);
});
$('#div1').mouseout(function() {
$('#div2').fadeOut(500);
});
$('#div2').hide().mouseout(function() {
$('#div2').fadeOut(500);
});
The problem is that the requirement of showing the second div persistently when moving the mouse from the first to the second div is not working - when moving the mouse from the first to the second div will raise the mouseout
of the first div. 问题是,显示了第二个div坚持从第一到第二个div移动鼠标时的要求是不工作-移动从第一个鼠标时的第二个div会提高
mouseout
第一个div的。
How could I possibly add this rule in my code? 如何在我的代码中添加此规则? I tried just doing http://jsfiddle.net/tC3ZL/1/ :
我尝试只做http://jsfiddle.net/tC3ZL/1/ :
$('#div2').mouseover(function() {
$('#div2').fadeIn(500);
});
but this makes the second div fade out and fade in when moving the mouse from the first to the second div, whilst it should just stay without any effects. 但这会使第二个div在将鼠标从第一个div移动到第二个div时淡出和淡入,而它应该保持不受影响。
Thanks in advance. 提前致谢。
Use this code instead of yours 使用此代码代替您的代码
$('#div1').mouseover(function() {
$('#div2').stop();
$('#div2').fadeIn(500);
});
$('#div2').hide().mouseout(function() {
$('#div2').fadeOut(500);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.