简体   繁体   English

当将鼠标移出两个div时隐藏div,但如果将鼠标悬停在一个或另一个上则不隐藏

[英]Hide a div, when mouseout two divs, but not if you are hover one or another

I have a two div with two id : 我有两个具有两个id的div:

<div id="somediv">
many Content
</div>
<div id="result></div>

i want to make something like that : 我想做这样的事情:

$("#somediv").bind("mouseleave",function(){
$('#result').fadeOut();
});
$("#result").bind("mouseleave",function(){
$('#result').fadeOut();
});

But i don't want that result dissapears if if move my mouse on the other div. 但是,如果我将鼠标移到另一个div上,我不希望该结果消失。 Is there a way to say : hide a div, when mouseout two divs, but not if you are hover one or another ? 有没有办法说:将div鼠标悬停两个div时隐藏div,但是如果将鼠标悬停在另一个div上则不能隐藏? The divs are not exactly superposed in the page. div在页面中并不完全重叠。 But They've got a common area. 但是他们有一个共同的领域。

Any ideas? 有任何想法吗?

Try: 尝试:

$("#somediv,#result").mouseenter(function(){
    $('#result').stop().fadeOut();
}).mouseleave(function(){
    $('#result').stop().fadeIn();
});

Another thing you can do is wrap both divs by another div such as: 您可以做的另一件事是用另一个div包装两个div,例如:

<div id="container">
    <div id="somediv">
        Many Content
    </div>
    <div id="result"></div>
</div>

and set the event on the parent: 并在父项上设置事件:

$('#container').mouseenter(function(){
    $('#result').stop().fadeIn();
}).mouseleave(function(){
    $('#result').stop().fadeOut();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM