日期:2014-05-16  浏览次数:20383 次

求助:鼠标停留1秒后,在鼠标后面显示一个div
怎么样让他停留1秒后才显示呢?
我的代码:
<div   id= "context "   style= "position:absolute;visibility:hidden>
This   is   some   context   shall   show   after   1   second.
</div>
<br>
<br>
<div   id= "tap ">
  <a   href= "# "     id= "link "   onmouseover= "delayShow(this) "   onmouseout= "delayHide() "> Mouse   Over   Here </a>  
</div>
<script   language=javascript>
//show  
function   showDiv(event,e)
{
        var   y=e.offsetTop;
        var   x=e.offsetLeft;
        while(e=e.offsetParent){
        t+=e.offsetTop;
        l+=e.offsetLeft;
        }
        var   oDiv=document.getElementById( "context ");
        oDiv.style.visibility= "visible ";
        oDiv.style.backgroundColor= "yellow ";
        oDiv.style.border= "solid   black   1px ";
        oDiv.style.left=x+30+ "px ";
        oDiv.style.top=y+20+ "px ";
}
//hide
function   hideDiv()
{
  var   oDiv=document.getElementById( "context ");
  oDiv.style.visibility= "hidden ";
}

function   delayHide(event)
{
    setTimeout( "hideDiv() ",1000);
}

function   delayShow(event)
{
    setTimeout( "showDiv(event,this) ",1000);
}
</script>
怎么好象不对啊,如何才能把事务指向div呢?

------解决方案--------------------
<div id= "context " style= "position:absolute;visibility:hidden>
-------------------------
<div id= "context " style= "position:absolute;visibility:hidden ">
=====================================================================
while(e=e.offsetParent){
t+=e.offsetTop;
l+=e.offsetLeft;
}
----------------------------------
t--> x
l--> y

------解决方案--------------------
setTimeout( "showDiv( " + event + ",this ) ",1000);
------解决方案--------------------
<div id= "context " style= "position:absolute;visibility:hidden ">
This is some context shall show after 1 second.
</div>
<br>
<br>
<div id= "tap ">
<a href= "# " id= "link " onmouseover= "delayShow(this) " onmouseout= "delayHide() "> Mouse Over Here </a>
</div>
<script language=javascript>
//show
function showDiv(event,e)
{
var y=e.offsetTop;
var x=e.offsetLeft;
while(e=e.offsetParent){
x+=e.offsetTop;
y+=e.offsetLeft;
}
var oDiv=document.getElementById( "context ");
oDiv.style.visibility= "visible ";
oDiv.style.backgroundColor= "yellow ";
oDiv.style.border= "solid black 1px ";
oDiv.style.left=x+30+ "px ";