效果比较简单了,呵呵。问题就是在鼠标移出菜单时,1秒后执行fnSmall(),但如果鼠标在1秒内移入菜单,那么取消执行,偶不会取消 =。=<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
var w = 0;
var h = 0;
function emotion(){
var oMenu = document.getElementById("menu");
if(w <= 50){
oMenu.style.display = "block";
fnLarge();
}
else{
fnSmall();
}
}
function fnLarge(){
var oMenu = document.getElementById("menu");
if(w < 200){
w += 50;
h += 25;
oMenu.style.width = w+"px";
oMenu.style.height = h+"px";
window.setTimeout("fnLarge()",10);
}
}
function fnSmall(){
var oMenu = document.getElementById("menu");
if(w > 0){
w -= 50;
h -= 25;
oMenu.style.width = w+"px";
oMenu.style.height = h+"px";
window.setTimeout("fnSmall()",5);
}
else{
oMenu.style.display = "none";
}
}
</script>
<style type="text/css">
body{
text-align: center;
}
p{
cursor: pointer;
margin: 0;
padding: 0;
font-size: 24px;
display: inline;
}
div a:link, div a:visited{
color: #666;
text-decoration: none;
}
div a:hover{
color: #FF6600;
text-decoration: underline;
}
div{
border: 2px solid #666;
background: #fff;
margin: 5px auto;
overflow: hidden;
display: none;
padding: 5px 10px;
}
ul,li{
margin: 0;
padding: 0;
}
li{
list-style: none;
}
li.title{
font-weight: bold;
}
</style>
</head>
<body>
<p onclick="emotion();">hello, emotion!</p>
<div id="menu" onmouseout="setTimeout('fnSmall()',1000)">
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="50" valign="top" align="left"><ul><li class="title">class</li><li><a href="#" onclick="fnSmall();">item</a></li><li><a href="#" onclick="fnSmall();">item</a></li><li><a href="#" onclick="fnSmall();">item</a></li><li></li>
    </ul></td>
    <td width="50" valign="top" align="left"><ul><li class="title">class</li><li><a href="#" onclick="fnSmall();">item</a></li><li><a href="#" onclick="fnSmall();">item</a></li><li><a href="#" onclick="fnSmall();">item</a></li><li><a href="#" onclick="fnSmall();">item</a></li></ul></td>
    <td width="50" valign="top" align="left"><ul><li class="title">class</li><li><a href="#" onclick="fnSmall();">item</a></li><li><a href="#" onclick="fnSmall();">item</a></li><li><a href="#" onclick="fnSmall();">item</a></li><li><a href="#" onclick="fnSmall();">item</a></li></ul></td>
    <td width="50" valign="top" align="left"><ul><li class="title">class</li><li><a href="#" onclick="fnSmall();">item</a></li><li><a href="#" onclick="fnSmall();">item</a></li>
    </ul></td>
  </tr>
</table>
</div>
</body>
</html>

解决方案 »

  1.   

    <!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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    body{
    text-align: center;
    }
    p{
    cursor: pointer;
    margin: 0;
    padding: 0;
    font-size: 24px;
    display: inline;
    }
    div a:link, div a:visited{
    color: #666;
    text-decoration: none;
    }
    div a:hover{
    color: #FF6600;
    text-decoration: underline;
    }
    div{
    border: 2px solid #666;
    background: #fff;
    margin: 5px auto;
    overflow: hidden;
    display: none;
    padding: 5px 10px;
    }
    ul,li{
    margin: 0;
    padding: 0;
    }
    li{
    list-style: none;
    }
    li.title{
    font-weight: bold;
    }
    </style>
    <script type="text/javascript">
    var w = 0;
    var h = 0;
    function emotion(){
    var oMenu = document.getElementById("menu");
    if(w <= 50){
    oMenu.style.display = "block";
    fnLarge();
    }
    else{
    fnSmall();
    }
    }
    function fnLarge(){
    var oMenu = document.getElementById("menu");
    if(w < 200){
    w += 50;
    h += 25;
    oMenu.style.width = w+"px";
    oMenu.style.height = h+"px";
    window.setTimeout("fnLarge()",10);
    }
    }
    function fnSmall(){
    var oMenu = document.getElementById("menu");
    if(w > 0){
    w -= 50;
    h -= 25;
    oMenu.style.width = w+"px";
    oMenu.style.height = h+"px";
    window.setTimeout("fnSmall()",5);
    }
    else{
    oMenu.style.display = "none";
    }
    }
    function a(){
    fnSmall();
    }
    function c(){
    a=function (){fnSmall();};
    setTimeout('a()',1000);
    }
    function b(){
    a=function (){};
    }
    </script>
    </head>
    <body>
    <p onclick="emotion();">hello, emotion!</p>
    <div id="menu" onmouseout="c()" onmouseover="b()">
    </div>
    </body>
    </html>
      

  2.   

    有点问题,改正:<!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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    body{
    text-align: center;
    }
    p{
    cursor: pointer;
    margin: 0;
    padding: 0;
    font-size: 24px;
    display: inline;
    }
    div a:link, div a:visited{
    color: #666;
    text-decoration: none;
    }
    div a:hover{
    color: #FF6600;
    text-decoration: underline;
    }
    div{
    border: 2px solid #666;
    background: #fff;
    margin: 5px auto;
    overflow: hidden;
    display: none;
    padding: 5px 10px;
    }
    ul,li{
    margin: 0;
    padding: 0;
    }
    li{
    list-style: none;
    }
    li.title{
    font-weight: bold;
    }
    </style>
    <script type="text/javascript">
    var w = 0;
    var h = 0;
    function emotion(){
    var oMenu = document.getElementById("menu");
    if(w <= 50){
    oMenu.style.display = "block";
    fnLarge();
    }
    else{
    fnSmall();
    }
    }
    function fnLarge(){
    var oMenu = document.getElementById("menu");
    if(w < 200){
    w += 50;
    h += 25;
    oMenu.style.width = w+"px";
    oMenu.style.height = h+"px";
    window.setTimeout("fnLarge()",10);
    }
    }
    function fnSmall(){
    var oMenu = document.getElementById("menu");
    if(w > 0){
    w -= 50;
    h -= 25;
    oMenu.style.width = w+"px";
    oMenu.style.height = h+"px";
    window.setTimeout("fnSmall()",5);
    }
    else{
    oMenu.style.display = "none";
    }
    }
    var has_out;
    function c(){//移开去
    has_out=setTimeout('fnSmall()',1000);
    }
    function b(){//移上去
    clearTimeout(has_out);
    }
    </script></head>
    <body>
    <p onclick="emotion();">hello, emotion!</p>
    <div id="menu" onmouseout="c()" onmouseover="b()">
    <table border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="50" valign="top" align="left"><ul><li class="title">class</li><li><a href="#" onclick="fnSmall();">item</a></li><li><a href="#" onclick="fnSmall();">item</a></li><li><a href="#" onclick="fnSmall();">item</a></li><li></li>
        </ul></td>
        <td width="50" valign="top" align="left"><ul><li class="title">class</li><li><a href="#" onclick="fnSmall();">item</a></li><li><a href="#" onclick="fnSmall();">item</a></li><li><a href="#" onclick="fnSmall();">item</a></li><li><a href="#" onclick="fnSmall();">item</a></li></ul></td>
        <td width="50" valign="top" align="left"><ul><li class="title">class</li><li><a href="#" onclick="fnSmall();">item</a></li><li><a href="#" onclick="fnSmall();">item</a></li><li><a href="#" onclick="fnSmall();">item</a></li><li><a href="#" onclick="fnSmall();">item</a></li></ul></td>
        <td width="50" valign="top" align="left"><ul><li class="title">class</li><li><a href="#" onclick="fnSmall();">item</a></li><li><a href="#" onclick="fnSmall();">item</a></li>
        </ul></td>
      </tr>
    </table>
    </div>
    </body>
    </html>