js制作可以延時(shí)消失的菜單
本文實(shí)例為大家分享了js可延時(shí)消失的菜單,供大家參考,具體內(nèi)容如下
代碼:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無(wú)標(biāo)題文檔</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 : '首頁(yè)', subtitle : ['首頁(yè)1','首頁(yè)2','首頁(yè)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>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
值得學(xué)習(xí)的JavaScript調(diào)試技巧分享
這篇文章主要給大家介紹了一些JavaScript調(diào)試技巧,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06JavaScript this綁定與this指向問(wèn)題的解析
本文主要介紹了JavaScript this綁定與this指向問(wèn)題的解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02教你如何自定義百度分享插件以及bshare分享插件的分享按鈕
在項(xiàng)目中我們常用到百度分享插件或者bshare分享插件,雖然官方都有自定義按鈕的功能,但是畢竟還是只有少數(shù)幾種,我們?nèi)绾蝸?lái)制作有自己特色的分享按鈕呢?2014-06-06JS中產(chǎn)生20位隨機(jī)數(shù)以0-9為例也可以是a-z A-Z
本節(jié)主要介紹了JS如何產(chǎn)生隨機(jī)數(shù),本例產(chǎn)生20位隨機(jī)數(shù)以0-9為例也可以是a-z A-Z,需要的朋友可以參考下2014-08-08JavaScript實(shí)現(xiàn)一個(gè)簡(jiǎn)易的計(jì)算器實(shí)例代碼
這篇文章主要介紹了JavaScript實(shí)現(xiàn)一個(gè)簡(jiǎn)易的計(jì)算器實(shí)例代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,一起跟隨小編過(guò)來(lái)看看吧2018-05-05可以自動(dòng)輪換的頁(yè)簽 tabs with auto play fucntion
HTML、CSS方面改寫(xiě)了一下結(jié)構(gòu),用了一個(gè)DL javascript方面可以選擇不斷自動(dòng)循環(huán),或者只循環(huán)一次的,點(diǎn)擊以后繼續(xù)循環(huán),或者停止循環(huán)2008-02-02