js+css实现三级导航菜单
本⽂实例为⼤家分享了js+css实现三级导航菜单的具体代码,供⼤家参考,具体内容如下
导航菜单hover事件⽤css实现相对容易,只需要将透明度更改即可,如果想要菜单有⼀个渐变的效果,然⽽可惜的是transition并不⽀持display,所以⽤opacity实现效果完全相同。
下⾯是⽤css实现的完整代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>三级导航菜单</title>
</head>
<style>
*{
margin: 0;
padding: 0;
}
body{
font-size: 16px;
background-color:#EDEDED ;
font-style: inherit;
color:#757576 ;
}
.main{
width: 1050px;
margin: 0 auto;
}
.fl{
float: left;
}
.fr{
float: right;
}
a{
text-decoration: none;
outline: none;
导航菜单color:#757576 ;
}
ul,ol{
list-style: none;
}
.clear{
clear: both;
}
.clearfix{
*zoom:1;
}
li{
float: left;
display: inline-block;
width: 120px;
height: 40px;
text-align: center;
line-height: 40px;
}
li a:hover{
color: red;
}
#frist {
opacity: 0;
}
#frist li{
float: none;
position: relative;
}
li a:hover{
color: red;
transition: all 0.5s;
}
:hover{
transition: all 2s;
}
#second {
opacity: 0;
margin: -40px 0 0 80px;
padding: 0px;
position: absolute;
}
#nav_one:hover #frist{
opacity:1;
transition: all 2s;
}
#nav_two:hover #second{
opacity:1;
transition: all 2s;
}
</style>
<body>
<div class="nav main">
<ul id="nav">
<li id="nav_one"><a href="#" >⼀级</a>
<ul id="frist">
<li id="nav_two" class="nav_two">
<a href="#" >⼆级</a>
<ul id="second">
<li><a href="#" >三级</a></li>
<li><a href="#" >三级</a></li>
<li><a href="#" >三级</a></li>
</ul>
</li>
<li class="nav_two"><a href="#" >⼆级</a></li>
<li class="nav_two"><a href="#" >⼆级</a></li>
</ul>
</li>
<li><a href="#" >⼀级</a></li>
<li><a href="#" >⼀级</a></li>
<li><a href="#" >⼀级</a></li>
<li><a href="#" >⼀级</a></li>
</ul>
</div>
</body>
</html>
js实现的相对⿇烦⼀点,但也可以,代替了css中hover效果。
<!--<script>
var one = ElementById("nav_one");
var frist = ElementById("frist");
var second = ElementById("second");
frist.style.opacity = "1";
ansition = "all 2s";
frist.style.WebkitTransition = "all 2s";
}
frist.style.opacity = "0";
ansition = "all 0.5s";
frist.style.WebkitTransition = "all 0.5s";
}
var two = ElementById("nav_two");
second.style.opacity = "1";
ansition = "all 2s";
second.style.WebkitTransition = "all 2s";
}
second.style.opacity = "0";
ansition = "all 0.5s";
second.style.WebkitTransition = "all 0.5s";
}
}
</script>-->
以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论