js+css實(shí)現(xiàn)三級(jí)導(dǎo)航菜單
本文實(shí)例為大家分享了js+css實(shí)現(xiàn)三級(jí)導(dǎo)航菜單的具體代碼,供大家參考,具體內(nèi)容如下
導(dǎo)航菜單hover事件用css實(shí)現(xiàn)相對(duì)容易,只需要將透明度更改即可,如果想要菜單有一個(gè)漸變的效果,然而可惜的是transition并不支持display,所以用opacity實(shí)現(xiàn)效果完全相同。
下面是用css實(shí)現(xiàn)的完整代碼:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>三級(jí)導(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="#" >一級(jí)</a> <ul id="frist"> <li id="nav_two" class="nav_two"> <a href="#" >二級(jí)</a> <ul id="second"> <li><a href="#" >三級(jí)</a></li> <li><a href="#" >三級(jí)</a></li> <li><a href="#" >三級(jí)</a></li> </ul> </li> <li class="nav_two"><a href="#" >二級(jí)</a></li> <li class="nav_two"><a href="#" >二級(jí)</a></li> </ul> </li> <li><a href="#" >一級(jí)</a></li> <li><a href="#" >一級(jí)</a></li> <li><a href="#" >一級(jí)</a></li> <li><a href="#" >一級(jí)</a></li> </ul> </div> </body> </html>
js實(shí)現(xiàn)的相對(duì)麻煩一點(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>-->
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- js左側(cè)三級(jí)菜單導(dǎo)航實(shí)例代碼
- JS中用三種方式實(shí)現(xiàn)導(dǎo)航菜單中的二級(jí)下拉菜單
- 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)文章
JavaScript實(shí)現(xiàn)動(dòng)畫打開(kāi)半透明提示層的方法
這篇文章主要介紹了JavaScript實(shí)現(xiàn)動(dòng)畫打開(kāi)半透明提示層的方法,涉及javascript操作DOM的相關(guān)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04基于JS實(shí)現(xiàn)數(shù)字+字母+中文的混合排序方法
這篇文章主要介紹了基于JS實(shí)現(xiàn)數(shù)字+字母+中文的混合排序方法的相關(guān)資料,非常不錯(cuò)具有參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06javascript瀑布流布局實(shí)現(xiàn)方法詳解
這篇文章主要介紹了javascript瀑布流布局實(shí)現(xiàn)方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了JavaScript實(shí)現(xiàn)瀑布流布局的樣式與具體功能代碼,需要的朋友可以參考下2016-02-02JS中通過(guò)slice()&substring()截取字符串前幾位的方法
在Javascript使用字符串中,我們不一定需要全部的字符串,這時(shí)就需要截取字符串,本文主要介紹js中截取字符串前幾位的兩種方法:1、使用slice() 方法;2、使用substring() 方法,本文通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友參考下吧2023-12-12深入理解JS中的微任務(wù)和宏任務(wù)的執(zhí)行順序及應(yīng)用場(chǎng)景
JavaScript中的任務(wù)分為宏任務(wù)和微任務(wù),它們的執(zhí)行順序會(huì)影響代碼的執(zhí)行結(jié)果。了解它們的機(jī)制可以幫助我們更好地理解事件循環(huán)和異步編程,避免出現(xiàn)一些意想不到的錯(cuò)誤2023-05-05wangEditor編輯器失去焦點(diǎn)后仍然可以在原位置插入圖片分析
本文給大家?guī)?lái)的是一款非常不錯(cuò)的富文本編輯器WangEditor,他最大的特點(diǎn)是它在ie6,7,8上都可以做到失去焦點(diǎn)后仍然可以在原位置插入圖片,而且代碼量很少,下面我們就來(lái)分析下他是如何實(shí)現(xiàn)的呢2015-05-05跟我學(xué)習(xí)javascript的prototype使用注意事項(xiàng)
跟我學(xué)習(xí)javascript的prototype使用注意事項(xiàng),介紹了在使用prototype的幾點(diǎn)注意事項(xiàng),需要的朋友可以參考下2015-11-11