简体   繁体   English

jQuery:鼠标悬停在背景div“通过”前景工具提示?

[英]jQuery: mouseover on a background div “through” a foreground tooltip?

I have a background div and a foreground div which fades in as the background is moused over, and fades out when the background is mousd out. 我有一个背景div和一个前景div,当背景被遮住时淡入,并在背景被淘汰时淡出。

But when the foreground fades in, it steals focus from the background and the tooltip ends up "flashing": 但是当前景淡入时,它会从背景中窃取焦点并且工具提示最终“闪烁”:

http://jsfiddle.net/ts97t/ http://jsfiddle.net/ts97t/

How do I keep the tooltip visible and stop the flashing? 如何保持工具提示可见并停止闪烁?

Thanks 谢谢

Mouse over me. 把鼠标放在我身上 This needs to stay visible, and not flash, until I mouse out of the green square! 这需要保持可见,而不是闪光,直到我鼠标离开绿色方块!

JQUERY JQUERY

$("#background").hover(function(){
 $("#tooltip").fadeIn();
},function(){
    $("#tooltip").fadeOut();
   });​

and if you want #tooltip overlaps the " Mouse over me " text. 如果你想#tooltip重叠“ Mouse over me ”文本。

#tooltip {
    display: none;
    width: 130px;
    height: 130px;
    background: red;
    top:0;
}

DEMO DEMO

second way 第二种方式

   var i=0;
$("#background").hover(function(){
     $("#tooltip").fadeIn();
    },function(){
        if (i==1) {
            $("#tooltip").fadeOut();
i=0;
        } 
    });

$('#tooltip').hover('',function(){
  i=1;

});

HTML HTML

<div id="background">Mouse over me.</div>
<div id="tooltip">This needs to stay visible, and not flash, until I mouse out of the green square!</div>

DEMO 2 演示2

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

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