jquery鼠标外出和鼠标离开问题

时间:2010-09-28 12:00:19

标签: jquery mouseover mouseleave

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js" type="text/javascript"></script>
</head>
<body>
    <div id="popupContact"  style="position:absolute;left:100px;top:100px;width:100px;height:50px;background-color:orange;border:1px solid red ;">
    </div>
    <div id="divtoshow" style="display:none;background-color:green; border:1px solid black;width:200px;height:100px;position:absolute;">
    dsfdssd <div><a href="#">rahul</a></div>
    </div>
</body>
</html>
<script  type='text/javascript'>
$(document).ready(function(){
    var popup_pos=$('#popupContact').offset();
    var timer;
     $("#popupContact").mouseover(function() {
        if(timer) {
            clearTimeout(timer);
            timer = null
           }
        timer = setTimeout(function() {
            if(!$("#VersionSelectField").is(':hidden')){
                $("#divtoshow").css('position',"absolute"); 
                $("#divtoshow").css('top',popup_pos.top-20);    
                $("#divtoshow").css('left',popup_pos.left-20);  
                $("#divtoshow").show();
                 $("#popupContact").hide();
            }

        }, 1000);

    });

     $("#divtoshow").mouseleave(function() {
            if(timer) {
                clearTimeout(timer);
                timer = null
               }
            timer = setTimeout(function() {
                $("#divtoshow").hide();
                 $("#popupContact").show();

            }, 500);
    });
});
</script>

嗨,我有下面的代码,当我鼠标悬停在popupcontact div上并突然鼠标移出div然后divtoshow div正在显示但我不想要那请帮助......

问:如何不显示divtoshow div而我突然将鼠标移出popupcontact div? 我想要延迟

2 个答案:

答案 0 :(得分:1)

怎么样?
$("#popupContact").mouseout(function() {  
    $("#divtoshow").hide();
    $("#popupContact").show();
});

答案 1 :(得分:0)

在mouseleave()

中的setTimeOut()中将500更改为0