js+css實(shí)現(xiàn)三級導(dǎo)航菜單
本文實(shí)例為大家分享了js+css實(shí)現(xiàn)三級導(dǎo)航菜單的具體代碼,供大家參考,具體內(nèi)容如下
導(dǎo)航菜單hover事件用css實(shí)現(xiàn)相對容易,只需要將透明度更改即可,如果想要菜單有一個(gè)漸變的效果,然而可惜的是transition并不支持display,所以用opacity實(shí)現(xiàn)效果完全相同。
下面是用css實(shí)現(xiàn)的完整代碼:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>三級導(dǎo)航菜單</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實(shí)現(xiàn)的相對麻煩一點(diǎn),但也可以,代替了css中hover效果。
<!--<script>
window.onload = function(){
var one = document.getElementById("nav_one");
var frist = document.getElementById("frist");
var second = document.getElementById("second");
one.onmouseover = function(){
frist.style.opacity = "1";
frist.style.transition = "all 2s";
frist.style.WebkitTransition = "all 2s";
}
one.onmouseout = function(){
frist.style.opacity = "0";
frist.style.transition = "all 0.5s";
frist.style.WebkitTransition = "all 0.5s";
}
var two = document.getElementById("nav_two");
two.onmouseover = function(){
second.style.opacity = "1";
second.style.transition = "all 2s";
second.style.WebkitTransition = "all 2s";
}
two.onmouseout = function(){
second.style.opacity = "0";
second.style.transition = "all 0.5s";
second.style.WebkitTransition = "all 0.5s";
}
}
</script>-->
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- js左側(cè)三級菜單導(dǎo)航實(shí)例代碼
- JS中用三種方式實(shí)現(xiàn)導(dǎo)航菜單中的二級下拉菜單
- JS實(shí)現(xiàn)選中當(dāng)前菜單后高亮顯示的導(dǎo)航條效果
- 一個(gè)js控制的導(dǎo)航菜單實(shí)例代碼
- js實(shí)現(xiàn)水平滾動(dòng)菜單導(dǎo)航
- 原生js做的手風(fēng)琴效果的導(dǎo)航菜單
- 可以媲美Flash的JS導(dǎo)航菜單
- 原生JS實(shí)現(xiàn)導(dǎo)航下拉菜單效果
- js實(shí)現(xiàn)多選項(xiàng)切換導(dǎo)航菜單的方法
- 用js實(shí)現(xiàn)的比較經(jīng)典實(shí)用的觸發(fā)型導(dǎo)航菜單
相關(guān)文章
JS實(shí)現(xiàn)微信"炸屎"大作戰(zhàn)功能
這篇文章主要介紹了JS實(shí)現(xiàn)微信 "炸屎"大作戰(zhàn),本文通過實(shí)例代碼圖文展示給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-07-07
js+css實(shí)現(xiàn)tab菜單切換效果的方法
這篇文章主要介紹了js+css實(shí)現(xiàn)tab菜單切換效果的方法,以實(shí)例形式完整講述了css與js的實(shí)現(xiàn)代碼,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-01-01
Typescript學(xué)習(xí)之接口interface舉例詳解
TypeScript是JavaScript的一個(gè)超集,主要提供了類型系統(tǒng)和對ES6+的支持,TypeScript的核心原則之一是對值所具有的結(jié)構(gòu)進(jìn)行類型檢查,這篇文章主要給大家介紹了關(guān)于Typescript學(xué)習(xí)之接口interface的相關(guān)資料,需要的朋友可以參考下2024-03-03
BootStrap Table后臺分頁時(shí)前臺刪除最后一頁所有數(shù)據(jù)refresh刷新后無數(shù)據(jù)問題
這篇文章主要介紹了BootStrap Table后臺分頁時(shí)前臺刪除最后一頁所有數(shù)據(jù)refresh刷新后無數(shù)據(jù)問題,需要的朋友可以參考下2016-12-12
javascript設(shè)計(jì)模式 – 工廠模式原理與應(yīng)用實(shí)例分析
這篇文章主要介紹了javascript設(shè)計(jì)模式 – 工廠模式,結(jié)合實(shí)例形式分析了javascript工廠模式基本概念、原理、定義、應(yīng)用場景及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2020-04-04
詳解JavaScript 浮點(diǎn)數(shù)運(yùn)算的精度問題
這篇文章主要介紹了詳解JavaScript 浮點(diǎn)數(shù)運(yùn)算的精度問題,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07

