<!-- 用js实现导航样式 -->
<!DOCTYPE html>
<html>
<head>小技巧</title>
<meta charset="utf-8">
<style type="text/css">
body{
padding:0;
font-size:10pt;
behavior:url(css/csshover.htc);/*补丁文件*/
}
.topmenu{
display: block;
width: 220px;
border: 2px solid #e4393c;
margin: 0;
padding: 0;
}
.topTitle{
height: 40px;
line-height: 40px;
background:#e4393c;
text-align: left;
font-size: 11pt;
font-weight: bold;
color: white;
padding-left: 20px;
}
.topmenu li{
height: 30px;
line-height: 30px;
font-size: 11pt;
list-style-type: none;
text-align: left;
padding-left: 8px;
z-index: 3;
background-image:url(1.png);/*没有原图*/
background-repeat: no-repeat;
background-position: right;
}
.topmenu li a{
text-decoration: none;
color: #313131;
}
.topmenu li a:hover{
text-decoration: underline;
font-weight: bold;
color: #e4393c;
}
.topmenu .lihover/*鼠标移动到上面时,应用的样式*/{
border: solid 1px #DDD;
border-right: 0;
box-shadow: 0 0 8px #DDD;/*外发光*/
-moz-box-shadow:0 0 8px #DDD;
-webkit-box-shadow:0 0 8px #DDD;
border-image: none;
height: 60px;
border-left: 4px solid #e4393c;
}
.submenu{
display: none;
width: 715px;
left: 220px;
position: absolute;
top: 40px;
border: 1px solid #DDD;
z-index: 4;
background: white;
box-shadow: 0 0 8px #DDD;/*外发光*/
-moz-box-shadow:0 0 8px #DDD;
-webkit-box-shadow:0 0 8px #DDD;
}
.leftdiv{
/*background:gray;*/
float: left;
margin: 5px;
width: 490px;
}
.rightdiv{
/*background:blue;*/
float: left;
margin: 5px;
width: 200px;
}
.topmenu .lihover .submenu{
/*悬浮层*/
display: block;
}
.topmenu .lihover span{
/*小白方框*/
background: white;
display: inline-block;
z-index: 20;
width: 20px;
height: 60px;
float: right;
position: relative;
}
.topmenu .lihover b{
display: block;
height: 30px;
line-height: 30px;
font-size: 10pt;
font-weight: normal;
}
.leftdiv dl{
display: block;
border-bottom: 1px solid #EEE;
padding-bottom: 6px;
overflow: hidden;
}
.leftdiv dl dt{
display: block;
float: left;
width: 60px;
text-align: right;
height: 22px;/*height: 14px;*/
line-height:22px; /*22px;line-height: 14px;*/
padding-right: 6px;
}
.leftdiv dl dt a{
color: #e4393c;
font-weight: bold;
text-decoration: underline;
font-size: 10px;
}
.leftdiv dl dd{
display: block;
overflow: hidden;
}
.leftdiv dl dd a{
display: block;
float: left;
border-left: 1px solid #ccc;
color: #737373;
font-size: 9pt;
padding: 0 8px;
height: 14px;
line-height: 14px;
margin:4px 0;/*思考:为什么不把dt直接设置成14px?分类有2行的时候,竖线连接在一起,行间距有2行*/
}
.rightdiv dl dd{
margin:3px 0;
}
.rightdiv dl dt{
color: #e4393c;
font-weight: bold;
font-size: 10pt;
}
.rightdiv dl dd a{
font-size: 9pt;
color: #737373;
line-height: 22px;
}
.rightdiv dl dd a:hover{
color: #737373;
font-weight: normal;
}
.topmenu li b{
/*提示菜单*/
display: none;
}
.rightpic{
position: relative;
right: -55px;
bottom: -45px;
}
</style>
</head>
<body>
<script type="text/javascript">
window.onload=function(){
var oli=document.getElementsByTagName("li");
for(var i=0;i<oli.length;i++){
oli[i].i=i;
oli[i].onmouseover=function(){
this.className ="lihover";
var h0=(this.i-1)*30+42;
var y=this.getElementsByTagName("div")[0].offsetHeight;//自身宽度
var h=this.getElementsByTagName("div")[0].style.top+y;
if(h<h0){
this.getElementsByTagName("div")[0].style.top=h0+"px";
}
if (y>550) {
this.getElementsByTagName("div")[0].style.top="3px";
}
};
oli[i].onmouseout=function(){
this.className =null;//null等价于""
};
}
};
</script>
<ul class="topmenu">
<div class="topTitle">全部商品分类</div>
<li><a href="#">图形、音响、数字商品</a><span></span>
<b><a href="#">免费</a>
<a href="#">小说</a>
<a href="#">励志与成长</a></b>
<div class="submenu">
<div class="leftdiv">
<dl>
<dt><a href="#">电子书</a></dt>
<dd><a href="#">免费</a>
<a href="#">小说</a>
<a href="#">励志与成长</a>
<a href="#">文学</a>
<a href="#">经管</a>
<a href="#">畅读VIP</a>
</dd>
</dl>
<dl>
<dt><a href="#">数字音乐</a></dt>
<dd><a href="#">通俗音乐</a>
<a href="#">古典音乐</a>
<a href="#">摇滚说唱</a>
<a href="#">爵士蓝调</a>
<a href="#">乡村民谣</a>
<a href="#">有声读物</a>
</dd>
</dl>
<dl>
<dt><a href="#">音像</a></dt>
<dd><a href="#">音乐</a>
<a href="#">影视</a>
<a href="#">教育音像</a>
<a href="#">游戏</a>
</dd>
</dl>
<dl>
<dt><a href="#">文艺</a></dt>
<dd><a href="#">小说</a>
<a href="#">文学</a>
<a href="#">青春文学</a>
<a href="#">传记</a>
<a href="#">艺术</a>
</dd>
</dl>
<dl>
<dt><a href="#">人文社科</a></dt>
<dd><a href="#">历史</a>
<a href="#">心理学</a>
<a href="#">政治军事</a>
<a href="#">国学古籍</a>
<a href="#">哲学宗教</a>
<a href="#">社会科学</a>
</dd>
</dl>
<dl>
<dt><a href="#">经管励志</a></dt>
<dd><a href="#">经济</a>
<a href="#">金融与投资</a>
<a href="#">管理</a>
<a href="#">励志与成功</a>
</dd>
</dl>
<dl>
<dt><a href="#">生活</a></dt>
<dd><a href="#"家教与育儿</a>
<a href="#">旅游/地图</a>
<a href="#">烹饪/美食</a>
<a href="#">时尚/美妆</a>
<a href="#">家居</a>
<a href="#">婚恋与两性</a>
<a href="#">娱乐/休闲</a>
<a href="#">健身与保健</a>
<a href="#">动漫/幽默</a>
<a href="#">体育/运动</a>
</dd>
</dl>
<dl>
<dt><a href="#">科技</a></dt>
<dd><a href="#">科普</a>
<a href="#">建筑</a>
<a href="#">医学</a>
<a href="#">工业技术</a>
<a href="#">电子/通信</a>
<a href="#">农林</a>
<a href="#">科学与自然</a>
</dd>
</dl>
<dl>
<dt><a href="#">少儿</a></dt>
<dd><a href="#">少儿</a>
<a href="#">0-2岁</a>
<a href="#">3-6岁</a>
<a href="#">7-10岁</a>
<a href="#">11-14岁</a>
</dd>
</dl>
<dl>
<dt><a href="#">教育</a></dt>
<dd><a href="#">教材</a>
<a href="#">中小学辅导</a>
<a href="#">考试</a>
<a href="#">外语学习</a>
</dd>
</dl>
<dl>
<dt><a href="#">其他</a></dt>
<dd><a href="#">英文原版书</a>
<a href="#">港台图书</a>
<a href="#">工具书</a>
<a href="#">套装书</a>
<a href="#">经管</a>
<a href="#">杂志/期刊</a>
</dd>
</dl>
</div>
<div class="rightdiv">
<dl>
<dd><a href="#"><img src="wii.png"></a></dd>
</dl>
<dl>
<dt>推荐品牌</dt>
<dd><a href="#">美的官方旗舰店</a></dd>
<dd><a href="#">苏泊尔旗舰店</a></dd>
<dd><a href="#">九阳旗舰店</a></dd>
<dd><a href="#">东菱旗舰店</a></dd>
<dd><a href="#">海尔统帅旗舰店</a></dd>
<dd><a href="#">小熊旗舰店</a></dd>
</dl>
<img class="rightpic" src="2.png">
</div>
</div>
</li>
<li><a href="#">家用电器</a><span></span>
<div class="submenu">
<div class="leftdiv">
<dl>
<dt><a href="#">大 家 电</a></dt>
<dd>
<a href="#">平板电视</a> <a href="#">空调</a> <a href="#">冰箱</a> <a href="#">洗衣机</a> <a
href="#">家庭影院</a> <a href="#">DVD</a> <a href="#">迷你音响</a> <a href="#">烟机/灶具</a>
<a href="#">热水器</a> <a href="#">消毒柜/洗碗机</a> <a href="#">酒柜/冷柜</a> <a href="#">家电配件</a>
</dd>
</dl>
<dl>
<dt><a href="#">生活电器</a></dt>
<dd>
<a href="#">电风扇</a> <a href="#">冷风扇</a> <a href="#">净化器</a> <a href="#">饮水机</a>
<a href="#">净水设备</a> <a href="#">挂烫机/熨斗</a> <a href="#">吸尘器</a> <a href="#">电话机</a>
<a href="#">插座</a> <a href="#">收录/音机</a> <a href="#">清洁机</a> <a href="#">加湿器</a>
<a href="#">除湿/干衣机</a> <a href="#">取暖电器</a> <a href="#">其它生活电器</a>
</dd>
</dl>
<dl>
<dt><a href="#">厨房电器</a></dt>
<dd>
<a href="#">电压力锅</a> <a href="#">电饭煲</a> <a href="#">豆浆机</a> <a href="#">面包机</a>
<a href="#">咖啡机</a> <a href="#">微波炉</a> <a href="#">料理/榨汁机</a> <a href="#">电烤箱</a>
<a href="#">电磁炉</a> <a href="#">电饼铛/烧烤盘</a> <a href="#">煮蛋器</a> <a href="#">酸奶机</a>
<a href="#">电水壶/热水瓶</a> <a href="#">电炖锅</a> <a href="#">多用途锅</a> <a href="#">果蔬解毒机</a>
<a href="#">其它厨房电器</a>
</dd>
</dl>
<dl>
<dt><a href="#">个护健康</a></dt>
<dd>
<a href="#">剃须刀</a> <a href="#">剃/脱毛器</a> <a href="#">口腔护理</
js实现京东商城导航
最新推荐文章于 2023-11-24 13:23:19 发布
本文详细介绍了如何利用JavaScript技术来实现京东商城风格的导航菜单。通过动态操作DOM元素,结合事件监听,创建了一个响应式的导航栏,实现了点击展开和收起子菜单的功能,增强了用户体验。
摘要由CSDN通过智能技术生成