Reputation: 375
I have two divs
close to each other. When I hover over div one, div two is showing.
If I don't mouse hover on div
two it should fadeout. Or if I move mouse from div
one to elsewhere then also div
two should fadeout.
$(".one").mouseover(function () {
$(".two").show();
});
$(".two").mouseleave(function () {
$(".two").fadeOut(1);
});
Upvotes: 0
Views: 347
Reputation: 441
Check this out.
$(".one").hover(function () {
$(".two").show();
},function(){
if($(".two:hover").length==0) {
$(".two").fadeOut();
}else{
$(".two").mouseleave(function () {
$(".two").fadeOut();
});
}
});
Upvotes: 0
Reputation: 375
I did it by my self.
$(".one").mouseover(function () {
$(".two").show();
});
$(".one").mouseleave(function () {
if($(".two").is(":hover")){
}else{
$(".two").fadeOut();
}
});
$(".two").mouseleave(function () {
if($(".one").is(":hover")){
}else{
$(".two").fadeOut();
}
});
Upvotes: -1
Reputation: 20626
You can add a mouseover
event on body and act according to the current target. This will close/hide the element, if the mouse hovers anywhere in the body excpet .one
and .two
$("body").mouseover(function (e) {
if(!($(e.target).is('.one') || $(e.target).is('.two'))){
$(".two").fadeOut();
}
});
Upvotes: 2
Reputation: 1646
Updated your Fiddle.
You could use another parent div
and bind events to it, instead of .one
and .two
.
Upvotes: 1