简体   繁体   English

在链接悬停显示div上,该字符显示在该div和链接的悬停上

[英]on link hover display div, which show on hover of that div and link

i have link and on link hover display div when leave cursor form div and link hide div using jQuery. 当离开光标表单div和使用jQuery链接隐藏div时,我有链接并且在链接悬停时显示div。 i have code for display it, how can i hide it while i leave cursor from these link and div.this is my html code. 我有显示它的代码,当我从这些链接和div离开光标时如何隐藏它。这是我的html代码。

 <a href="javascript:void(0);" id="show_div">2 items</a>
 <div id="dropcart">contents</div>

<script type="text/javascript">
$(document).ready(function(){
 $("#show_div").hover(function(){
       $("#dropcart").fadeIn();
    });                 
});

$("#show_div").hover(function(){
     $("#dropcart").fadeIn();
});

$("#dropcart").mouseleave(function(){
    if($("#show_div").is(':hover') === false)
    $("#dropcart").fadeOut("fast"); 
});

demo 演示

EDIT: (For the downvoters and OP) 编辑:(对于下降投票者和OP)

I misunderstood the question. 我误解了这个问题。 My suggestion, then, would be to use timeouts. 因此,我的建议是使用超时。

.hover(function(){ clearTimeout(window["timeoutVar"]); $("#dropcart").fadeIn(); },function(){window["timeoutVar"]=setTimeout(function(){ $("#dropcart").fadeout(); },50);});

Then apply that .hover to the div, also. 然后,也将.hover应用于div。 That way, the div will fade out after a 50-millisecond delay IF the user does not hover over it, which will cancel the timeout (and prevent the fadeout). 这样,如果用户未将div悬停在div上,它会在经过50毫秒的延迟后淡出,这将取消超时(并防止淡出)。

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

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