<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">javascript
<html xmlns="http://www.w3.org/1999/xhtml">css
<head>html
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />java
<title>無標題文檔</title>json
<style type="text/css">框架
*{ margin:0px; padding:0px; font-size:12px;}ide
ul li{ list-style:none;}ui
a{ text-decoration:none;}this
#nav{ width:980px; margin:0 auto;}spa
#nav li{
height:36px; line-height:36px; background:#666666; text-align:center;
width:120px; position:relative; float:left; margin-right:10px;
}
#nav li a{ color:#FFFFFF; display:block; font-weight:bold;}
#nav ul{ height:0px; overflow:hidden; position:absolute; left:0px;}
#nav ul li{ background:#003366; height:28px; line-height:28px;}
#nav ul li a{ color:#FFFFFF; display:block; font-weight:normal;}
.clear{ zoom:1;}
.clear:after{ content:""; display:block; clear:both;}
</style>
<script language="javascript">
window.onload=function()
{
var oNav=document.getElementById("nav");//獲取導航元素節點
var oLi=oNav.children;//獲取Nav下面的全部的li元素 返回的是一個集合
for(var i=0;i<oLi.length;i++)
{
//當鼠標移過去的時候 發生移動事件
oLi[i].onmouseover=function()
{
var oUl=this.getElementsByTagName("ul")[0];//獲取當前li下面的第一個<ul>節點
var oList=oUl.children;//獲取<ul>下面的子元素 <li>
var offsetHeight=oList[0].offsetHeight; //計算0下標 也就是第一個元素的高度 28px
var iTargetHeight=(oList.length * offsetHeight) //至關於li的個數 * 每一個 li的高度 height 5*28=????
//開始調用完美運動框架....
startMove(oUl,{"height":iTargetHeight});
}
//當鼠標移開的時候 就關閉
oLi[i].onmouseout=function()
{
var oUl=this.getElementsByTagName("ul")[0];//獲取當前li下面的第一個<ul>節點
startMove(oUl,{"height":0});
}
}
}
</script>
</head>
<body>
<br/><br/><br/><br/><br/>
<ul id="nav" class="clear">
<li>
<a href="#">產品展現</a>
<ul>
<li><a href="#">LED天花燈</a></li>
<li><a href="#">LED天花燈</a></li>
<li><a href="#">LED天花燈</a></li>
<li><a href="#">LED天花燈</a></li>
<li><a href="#">LED天花燈</a></li>
<li><a href="#">LED天花燈</a></li>
</ul>
</li>
<li>
<a href="#">新聞中心</a>
<ul>
<li><a href="#">LED天花燈</a></li>
<li><a href="#">LED天花燈</a></li>
<li><a href="#">LED天花燈</a></li>
<li><a href="#">LED天花燈</a></li>
<li><a href="#">LED天花燈</a></li>
</ul>
</li>
<li>
<a href="#">聯繫咱們</a>
<ul>
<li><a href="#">LED天花燈</a></li>
<li><a href="#">LED天花燈</a></li>
<li><a href="#">LED天花燈</a></li>
<li><a href="#">LED天花燈</a></li>
</ul>
</li>
</ul>
<div style="width:980px; background:#666666; margin:0 auto; margin-top:10px; padding:50px 0px;" class="clear">
asdfasdf<br/>
asdfasdf<br/>
asdfasdf<br/>
asdfasdf<br/>
asdfasdf<br/>
asdfasdf<br/>
asdfasdf<br/>
asdfasdf<br/>
asdfasdf<br/>
asdfasdf<br/>
asdfasdf<br/>
asdfasdf<br/>
asdfasdf<br/>
asdfasdf<br/>
asdfasdf<br/>
asdfasdf<br/>
asdfasdf<br/>
asdfasdf<br/>
asdfasdf<br/>
asdfasdf<br/>
asdfasdf<br/>
asdfasdf<br/>
asdfasdf<br/>
</div>
</body>
</html>
<script language="javascript">
function startMove(obj, json, fn) {
clearInterval(obj.iTimer);
var iCur = 0;
var iSpeed = 0;
obj.iTimer = setInterval(function() {
var iBtn = true;
for ( var attr in json ) {
var iTarget = json[attr];
if (attr == 'opacity') {
iCur = Math.round(css( obj, 'opacity' ) * 100);
} else {
iCur = parseInt(css(obj, attr));
}
iSpeed = ( iTarget - iCur ) / 8;
iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);
if (iCur != iTarget) {
iBtn = false;
if (attr == 'opacity') {
obj.style.opacity = (iCur + iSpeed) / 100;
obj.style.filter = 'alpha(opacity='+ (iCur + iSpeed) +')';
} else {
obj.style[attr] = iCur + iSpeed + 'px';
}
}
}
if (iBtn) {
clearInterval(obj.iTimer);
fn && fn.call(obj);
}
}, 20);
}
function css(obj, attr) {
if (obj.currentStyle) {
return obj.currentStyle[attr];
} else {
return getComputedStyle(obj, false)[attr];
}
}
</script>