横下拉菜单setTimeout应用

来源:互联网 发布:淘宝情趣内衣好评50字 编辑:程序博客网 时间:2024/05/16 10:57

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>setTimeout应用</title>    <script type="text/javascript" src="jquery-1.7.min.js"></script><script type="text/javascript">var get = {byId: function(id) {return document.getElementById(id)},byClass: function(sClass, oParent) {var aClass = [];var reClass = new RegExp("(^| )" + sClass + "( |$)");var aElem = this.byTagName("*", oParent);for (var i = 0; i < aElem.length; i++) reClass.test(aElem[i].className) && aClass.push(aElem[i]);return aClass},byTagName: function(elem, obj) {return (obj || document).getElementsByTagName(elem)}};window.onload = function (){var oNav = get.byId("nav01");var aLi = get.byTagName("li", oNav);var aSubNav = get.byClass("subnav", oNav);var oSubNav = oEm = timer = null;var i = 0;if(!aSubNav)return;for (i = 0; i < aLi.length; i++){aLi[i].onmouseover = function (){for (i = 0; i < aSubNav.length; i++)aSubNav[i].style.display = "none";oSubNav = get.byClass("subnav", this)[0];          oEm = get.byTagName("em", this)[0];             if(!oSubNav)return;oSubNav.style.display = "block";oNav.offsetWidth - this.offsetLeft > oSubNav.offsetWidth ?oSubNav.style.left = this.offsetLeft + "px" :oSubNav.style.right = 0;oEm.style.left = this.offsetLeft - oSubNav.offsetLeft + 35 + "px";clearTimeout(timer);             oSubNav.onmouseover = function (event){(event || window.event).cancelBubble = true;clearTimeout(timer)}};aLi[i].onmouseout = function (){  timer = setTimeout(function () { if(!oSubNav)return;oSubNav.style.display = "none"},300)}}};</script></head><body><style>*{margin:0;padding:0;}body{font:12px/1.5 Arial;}ul,li{list-style-type:none;}#wrap{ width:950px; height:76px; background:#C60; margin:0 auto; position:relative;}#nav{position:absolute; bottom:0px; right:0px; }#nav ul{height:36px;line-height:36px; float:right; background:#DDD;  position:relative;}#nav ul li{float:left;}#nav ul li a{font-size:14px;color:#fff; display:inline-block; padding:0 12px;text-decoration:none;}#nav ul li a:hover{ background:#000;}#nav .subnav{display:none; position:absolute; top:41px; width:auto!important;min-width:110px;height:27px;line-height:27px;white-space:nowrap; background:#00F;}#nav .subnav p{ padding-left:9px;}#nav .subnav p span{display:block;color:#235e99;}#nav .subnav p a{font-size:12px;display:inline;color:#FFF;text-decoration:none;padding:0 4px;}#nav .subnav p a:hover{font-weight:400; text-decoration:none; background:none;}#nav .subnav .arrow{position:absolute;top:-10px;left:-10px;display:block;border: solid 5px;font-size: 0;line-height: 0;width: 0;height: 0; border-color: transparent transparent  #f60 transparent;}</style><div id="wrap">    <div id="nav">        <ul id="nav01">            <li><a href="javascript:;">站长之家</a><div class="subnav">                    <em class="arrow"></em>                    <p>                                <span>                            <a href="javascript:;">业界动态</a>|                            <a href="javascript:;">收购融资</a>|                            <a href="javascript:;">门户动态</a>|                            <a href="javascript:;">搜索引擎</a>|                            <a href="javascript:;">网络游戏</a>|                            <a href="javascript:;">电子商务</a>|                            <a href="javascript:;">广告传媒</a>|                            <a href="javascript:;">厂商开发</a>                        </span>                    </p>                </div> </li>            <li>                <a href="javascript:;">行业资讯</a>                           </li>            <li>                <a href="javascript:;">站长在线</a>                <div class="subnav" style="visibility: hidden;">                    <em class="arrow" style="visibility: hidden;"></em>                   <p>                        <span>                            <a href="javascript:;">站长报道</a>|                            <a href="javascript:;">好站推荐</a>|                            <a href="javascript:;">站长聚会</a>|                            <a href="javascript:;">站长访谈</a>|                            <a href="javascript:;">站长茶馆</a>|                            <a href="javascript:;">网站排行</a>                        </span>                    </p>                </div>            </li>            <li>                <a href="javascript:;">网站运营</a>                <div class="subnav">                    <em class="arrow"></em>                    <p>                                <span>                            <a href="javascript:;">建站经验</a>|                            <a href="javascript:;">策划盈利</a>|                            <a href="javascript:;">搜索优化</a>|                            <a href="javascript:;">网站推广</a>|                            <a href="javascript:;">免费资源</a>                        </span>                    </p>                </div>            </li>            <li>                <a href="javascript:;">设计在线</a>                <div class="subnav">                    <em class="arrow"></em>                    <p>                                <span>                            <a href="javascript:;">酷站推荐</a>|                            <a href="javascript:;">网页设计</a>|                            <a href="javascript:;">WEB标准</a>|                            <a href="javascript:;">视频处理</a>|                            <a href="javascript:;">设计活动</a>                        </span>                    </p>                </div>            </li>            <li>                <a href="javascript:;">网络编程</a>                <div class="subnav">                    <em class="arrow"></em>                    <p>                                <span>                            <a href="javascript:;">Asp编程</a>|                            <a href="javascript:;">Php编程</a>|                            <a href="javascript:;">.Net编程</a>|                            <a href="javascript:;">Xml编程</a>|                            <a href="javascript:;">Access</a>|                            <a href="javascript:;">Mssql</a>|                            <a href="javascript:;">Mysql</a>                        </span>                    </p>                </div>            </li>            <li>                <a href="javascript:;">联盟资讯</a>                <div class="subnav">                    <em class="arrow"></em>                    <p>                                <span>                            <a href="javascript:;">联盟动态</a>|                            <a href="javascript:;">联盟介绍</a>|                            <a href="javascript:;">联盟点评</a>|                            <a href="javascript:;">网赚技巧</a>                        </span>                    </p>                </div>            </li>            <li>                <a href="javascript:;">服务器</a>                <div class="subnav">                    <em class="arrow"></em>                    <p>                                <span>                            <a href="javascript:;">Web服务器</a>|                            <a href="javascript:;">Ftp服务器</a>|                            <a href="javascript:;">Mail服务器</a>|                            <a href="javascript:;">Dns服务器</a>|                            <a href="javascript:;">Win服务器</a>|                            <a href="javascript:;">Linux服务器</a>|                            <a href="javascript:;">安全防护</a>|                            <a href="javascript:;">虚拟主机</a>                        </span>                    </p>                </div>            </li>                </ul>        </div></div></body></html>