摘要:<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>三級下拉菜單</title> <script type="text/javascript" src="jquery-3.3.1
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>三級下拉菜單</title>
<script type="text/javascript" src="jquery-3.3.1.min.js"></script>
<style type="text/css">
*{margin: 0px;padding: 0px;}
.menu { width:600px;height: 35px;margin: 0px auto;background: #000; margin-top: 20px;color: #fff; border:1px solid #ccc;border-radius: 5px; position: relative;}
ul{ list-style: none;z-index:20;}
ul li {width: 100px;height: 35px;line-height: 35px;text-align: center;float: left;border-right: 1px solid #ccc;cursor: pointer;margin: 0px auto; font-weight: solid;}
.twobox li {width: 100px;height: 30px;line-height: 30px;background: #2D2D2D;color: #A9A9A9; font-size: 14px;position: relative;border:0px;}
.twobox li:hover {background: #000;color: #fff;}
.three {position: absolute; top: 0px;left: 100px;}
.three li {width: 99px;height: 30px;line-height: 30px;border: 0px;}
.block{z-index:10;width:90px;height:2px;background:#fff;position:absolute;top:31px;clear: both;margin: 0px 5px}
</style>
<script type="text/javascript">
//改變標(biāo)簽的背景顏色的函數(shù)
function changeColor(tag) {
var len=document.getElementsByTagName(tag).length
for(var i=0;i<len;i++){
document.getElementsByTagName(tag)[i].style.backgroundColor='rgb('+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+')'
}
}
$(function(){
//隱藏二級與三級下拉菜單
$('.twobox').hide()
$('.three').hide()
//當(dāng)鼠標(biāo)移動到包含二級菜單的一級菜單時顯示當(dāng)前二級菜單
$('.one li').mouseover(function(){
$(this).find('.twobox').slideDown(500)
})
//當(dāng)鼠標(biāo)移出包含二級菜單的一級菜單時隱藏當(dāng)前二級菜單
$('.one li').mouseleave(function(){
$(this).find('.twobox').slideUp(500)
})
//當(dāng)鼠標(biāo)移動到包含三級菜單的二級菜單時顯示當(dāng)前三級菜單
$('.two').mouseover(function(){
$(this).find('.three').slideDown(500)
})
//當(dāng)鼠標(biāo)移出包含三級菜單的二級菜單時隱藏當(dāng)前三級菜單
$('.two').mouseleave(function(){
$(this).find('.three').slideUp(500)
})
//調(diào)用函數(shù)獲取隨機顏色
changeColor('li')
//當(dāng)鼠標(biāo)在上面是
$('li').mouseover(function(){
$bg=$(this).css('backgroundColor')
$(this).css('box-shadow','0px 0px 20px '+$bg)
$(this).css('border-radius','20px ')
})
//當(dāng)鼠標(biāo)離開的時候
$('li').mouseleave(function(){
$(this).css('box-shadow','none')
$(this).css('border-radius','0px')
})
$('li').hover(
function(){
$x=parseInt($(this).attr('name'))*100
$('.block').stop().animate({left:$x+'px'},300)
},
function(){
$('.block').stop().animate({left:'0px'},300)
}
)
})
</script>
</head>
<body>
<div class="menu">
<ul class="one"><!-- 一級下拉菜單 one -->
<li name="0">首 頁 </li>
<li name="1">商品分類
<ul class="twobox"><!-- 二級下拉菜單 twobox-->
<li class="two">男人
<ul class="three"><!--三級下拉菜單 three-->
<li>外套</li>
<li>情侶裝</li>
<li>夾克</li>
<li>毛衣</li>
</ul>
</li>
<li class="two">箱包
<ul class="three"><!--三級下拉菜單 three-->
<li>產(chǎn)品1.1</li>
<li>產(chǎn)品1.2</li>
<li>產(chǎn)品1.3</li>
<li>產(chǎn)品1.4</li>
</ul>
</li>
<li class="two">數(shù)碼
<ul class="three">
<li>電腦</li>
<li>手機</li>
<li>相機</li>
<li>手表</li>
</ul>
</li>
<li>女人</li>
</ul>
</li>
<li name="2">我的淘寶
<ul class="twobox">
<li>以買到的寶貝</li>
<li class="two">我的足跡
</li>
<li>我的上新</li>
<li>淘寶達(dá)人</li>
</ul>
</li>
<li name="3">購物車</li>
<li name="4">收藏夾</li>
</ul>
<div class="block" ></div>
</div>
</body>
</html>
批改老師:滅絕師太批改時間:2018-11-22 09:07:26
老師總結(jié):沒毛病!完成的很好,布局邏輯清晰,知識點比較綜合