最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

js制作可以延時(shí)消失的菜單

 更新時(shí)間:2017年01月13日 08:38:11   作者:光明大神棍  
這篇文章主要為大家詳細(xì)介紹了基于JavaScript制作可以延時(shí)消失的菜單,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了js可延時(shí)消失的菜單,供大家參考,具體內(nèi)容如下

代碼:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標(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 : '首頁', 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)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

炉霍县| 孙吴县| 福泉市| 喀喇沁旗| 班玛县| 锡林郭勒盟| 龙井市| 镇安县| 吴忠市| 营山县| 嵩明县| 松滋市| 望奎县| 华阴市| 神农架林区| 沾化县| 体育| 远安县| 德保县| 会宁县| 南溪县| 岚皋县| 土默特左旗| 定兴县| 阿拉善右旗| 枣阳市| 肃宁县| 贵南县| 墨脱县| 西安市| 正安县| 涞水县| 资中县| 贡觉县| 敦煌市| 会理县| 班玛县| 石嘴山市| 琼海市| 黎平县| 梁河县|