js制作可以延時消失的菜單
更新時間:2017年01月13日 08:38:11 作者:光明大神棍
這篇文章主要為大家詳細介紹了基于JavaScript制作可以延時消失的菜單,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了js可延時消失的菜單,供大家參考,具體內(nèi)容如下
代碼:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題文檔</title> <style> *{padding:0;margin:0;} ul{list-style:none;} a{text-decoration:none;} #menu{height:200px;border:1px solid #ccc;margin:40px auto;position:relative;} #title{position:absolute;left:0;top:0;height:50px;border:1px solid yellow;background:blue;} #title li{text-align:center;width:80px;height:30px;line-height:30px;float:left;background:#f1f1f1;border-radius:10px;color:#000;font-weight:bold;margin:10px 5px;cursor:pointer;} #subtitle{height:30px;;border:1px solid #ccc;border-radius:10px;position:absolute;top:60px;left:10px;} #subtitle:before{content:'';position:absolute;border-top:7px solid transparent;border-right:7px solid transparent;border-bottom:9px solid #ccc;border-left:7px solid transparent;top:-16px;left:30px;} #subtitle:after{content:'';position:absolute;border-top:7px solid transparent;border-right:7px solid transparent;border-bottom:9px solid #fff;border-left:7px solid transparent;top:-15px;left:30px;} #subtitle a{display:inline-block;height:20px;line-height:20px;margin:5px 5px;float:left;} #subtitle a:hover{text-decoration:underline;} </style> <script> window.onload = function () { var title = document.getElementById('title'); var subtitle = document.getElementById('subtitle'); var aA = subtitle.getElementsByTagName('a'); var aLi = title.getElementsByTagName('li'); var arr = [ { title : '首頁', subtitle : ['首頁1','首頁2','首頁3']}, { title : '關(guān)于我們', subtitle : ['關(guān)于我們1','關(guān)于我們2','關(guān)于我們3','關(guān)于我們4','關(guān)于我們5']}, { title : '課程', subtitle : ['課程1','課程2','課程3']}, { title : '新聞', subtitle : ['新聞1','新聞2']}, ]; var timer = null; for ( var i = 0; i < arr.length; i++ ) { var oLi = document.createElement('li'); oLi.innerHTML = arr[i].title; oLi.index = i; oLi.onmouseover = function () { var width = parseInt(getStyle(this,'width')); var marginRight = parseInt(getStyle(this,'marginRight')); clearTimeout(timer); subtitle.innerHTML = ''; createA(this.index); subtitle.style.left = 10 + (width + marginRight) * this.index + 'px'; subtitle.style.display = 'block'; } oLi.onmouseout = function () { timer = setTimeout(function () { subtitle.style.display = 'none'; }, 100); } title.appendChild(oLi); } subtitle.onmouseover = function () { clearTimeout(timer); this.style.display = 'block'; } subtitle.onmouseout = function () { this.style.display = 'none'; } createA(0); function createA(index){ for ( var j = 0; j < arr[index].subtitle.length; j++ ){ var oA = document.createElement('a'); oA.innerHTML = arr[index].subtitle[j]; subtitle.appendChild(oA); } } function getStyle(ele, attr) { return ele.currentStyle ? ele.currentStyle[attr] : getComputedStyle(ele,0)[attr]; } } </script> </head> <body> <div id="menu"> <ul id="title"> </ul> <div id="subtitle"> </div> </div> </body> </html>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
值得學(xué)習(xí)的JavaScript調(diào)試技巧分享
這篇文章主要給大家介紹了一些JavaScript調(diào)試技巧,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06教你如何自定義百度分享插件以及bshare分享插件的分享按鈕
在項目中我們常用到百度分享插件或者bshare分享插件,雖然官方都有自定義按鈕的功能,但是畢竟還是只有少數(shù)幾種,我們?nèi)绾蝸碇谱饔凶约禾厣姆窒戆粹o呢?2014-06-06JS中產(chǎn)生20位隨機數(shù)以0-9為例也可以是a-z A-Z
本節(jié)主要介紹了JS如何產(chǎn)生隨機數(shù),本例產(chǎn)生20位隨機數(shù)以0-9為例也可以是a-z A-Z,需要的朋友可以參考下2014-08-08JavaScript實現(xiàn)一個簡易的計算器實例代碼
這篇文章主要介紹了JavaScript實現(xiàn)一個簡易的計算器實例代碼,具有很好的參考價值,希望對大家有所幫助,一起跟隨小編過來看看吧2018-05-05可以自動輪換的頁簽 tabs with auto play fucntion
HTML、CSS方面改寫了一下結(jié)構(gòu),用了一個DL javascript方面可以選擇不斷自動循環(huán),或者只循環(huán)一次的,點擊以后繼續(xù)循環(huán),或者停止循環(huán)2008-02-02