本文實例講述了js實現的黑背景灰色二級導航選單效果程式碼。分享給大家供大家參考。具體如下:
這是一款js實現的黑色背景灰色二級導航選單,相容於IE6、firefox的js css橫向二極導航選單。挺簡潔,不過很清新,二級選單是水平顯示在主選單的下方,採用流行的微軟雅黑字體,若不想用這種字體,可換成預設的宋體即可。
運作效果截圖如下:
線上示範網址如下:
http://demo.jb51.net/js/2015/js-black-bgcolor-2level-nav-style-codes/
具體程式碼如下:
<!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"> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312"> <TITLE>兼容IE6、firefox的灰色横向二极导航菜单代码</TITLE> <style type=text/css> BODY { background:#26272b;} a{ color:#FFFFFF} UL {LIST-STYLE-TYPE: none;padding:0px;margin:0px;} LI {FONT-SIZE: 12px; COLOR: #333; LINE-HEIGHT: 1.5em; FONT-FAMILY: "微软雅黑", Arial, Verdana;} .hide {DISPLAY: none} #mainmenu_top{width:980px; margin:0 auto;BACKGROUND: url('images/nav_bg.gif') bottom repeat-x;HEIGHT: 40px; } #mainmenu_top UL{} #mainmenu_top UL LI {FLOAT: left;} #mainmenu_top UL LI A {WIDTH: 100px;CURSOR: pointer;line-HEIGHT:32px;padding:6px 0 2px;text-decoration: none;DISPLAY: block;COLOR: #fff;TEXT-ALIGN: center; FONT-WEIGHT: bold;} #mainmenu_top .menu-lft {padding-left:10px;background:url('images/nav_l.gif') no-repeat left bottom;height:40px;} #mainmenu_top .menu-rht {background:url('images/nav_r.gif') no-repeat right bottom;height:40px;} #mainmenu_top UL LI .menuhover {BACKGROUND: url('images/nav_hover.gif') bottom repeat-x; COLOR: #000;} #mainmenu_top UL LI.home{BACKGROUND: url('images/nav_home.gif') center bottom no-repeat;} #mainmenu_bottom {width:980px; margin:0 auto;height:32px;line-height:32px;display:block;overflow:hidden;BACKGROUND:#fff;} #mainmenu_bottom UL LI { FLOAT: left; MARGIN-LEFT:12px;padding:0 12px;HEIGHT: 32px;} #mainmenu_bottom UL LI A {COLOR: #313131; LINE-HEIGHT: 32px;PADDING-RIGHT: 18px;DISPLAY: block;text-decoration: none; background:url('images/line.gif') no-repeat right bottom;} #mainmenu_bottom UL LI A:hover {text-decoration: underline;} </style> <SCRIPT type=text/javascript> var waitting = 1; var secondLeft = waitting; var timer; var sourceObj; var number; function getObject(objectId)//获取id的函数 { if(document.getElementById && document.getElementById(objectId)) { // W3C DOM return document.getElementById(objectId); } else if (document.all && document.all(objectId)) { // MSIE 4 DOM return document.all(objectId); } else if (document.layers && document.layers[objectId]) { // NN 4 DOM.. note: this won't find nested layers return document.layers[objectId]; } else { return false; } } function SetTimer()//主导航时间延迟的函数 { for(j=1; j <10; j++){ if (j == number){ if(getObject("mm"+j)!=false){ getObject("mm"+ number).className = "menuhover"; getObject("mb"+ number).className = ""; } } else{ if(getObject("mm"+j)!=false){ getObject("mm"+ j).className = ""; getObject("mb"+ j).className = "hide"; } } } } function CheckTime()//设置时间延迟后 { secondLeft--; if ( secondLeft == 0 ) { clearInterval(timer); SetTimer(); } } function showM(thisobj,Num)//主导航鼠标滑过函数,带时间延迟 { number = Num; sourceObj = thisobj; secondLeft = 1; timer = setTimeout('CheckTime()',100); } function OnMouseLeft()//主导航鼠标移出函数,清除时间函数 { clearInterval(timer); } </SCRIPT> <!--导航开始--> <DIV id=mainmenu_body> <!--主导航开始--> <DIV id=mainmenu_top> <div class="menu-lft"><div class="menu-rht"> <UL> <LI class="home"><A id=mm1 onmouseover=showM(this,1); onmouseout=OnMouseLeft(); href="#" target=_parent>网站首页</A> </LI> <LI><A id=mm2 onmouseover=showM(this,2); onmouseout=OnMouseLeft(); href="#" target=_parent>JS代码</A> </LI> <LI><A id=mm3 onmouseover=showM(this,3); onmouseout=OnMouseLeft(); href="#" target=_parent>电子商务</A> </LI> <LI><A id=mm4 onmouseover=showM(this,4); onmouseout=OnMouseLeft(); href="#" target=_parent>脚本下载</A> </LI> <LI><A id=mm5 onmouseover=showM(this,5); onmouseout=OnMouseLeft(); href="#" target=_parent>建站技巧</A> </LI> <LI><A id=mm6 onmouseover=showM(this,6); onmouseout=OnMouseLeft(); href="#" target=_parent>CSS技巧</A> </LI> <LI><A id=mm7 onmouseover=showM(this,7); onmouseout=OnMouseLeft(); href="#" target=_parent>CSS导航菜单</A> </LI> <LI><A id=mm8 onmouseover=showM(this,8); onmouseout=OnMouseLeft(); href="#" target=_parent>网络营销</A> </LI> <LI><A id=mm9 onmouseover=showM(this,9); onmouseout=OnMouseLeft(); href="#" target=_parent>SEO优化</A> </LI></UL> </DIV></DIV> </DIV> <!--子导航导航开始--> <DIV id=mainmenu_bottom> <UL class=hide id=mb1> <LI><A href="#">2012年元旦网站推广惊喜促销价</A> </LI> <LI><A href="#">网站公告:脚本之家7年了</A> </LI> </UL> <UL class=hide id=mb2> <LI><A href="#" target=_parent>脚本之家</A> </LI> <LI><A href="#" target=_parent>脚本之家</A> </LI> <LI><A href="#" target=_parent>脚本之家</A> </LI> <LI><A href="#" target=_parent>脚本之家</A> </LI> <LI><A href="#" target=_parent>脚本之家</A> </LI> <LI><A href="#" target=_parent>网页特效</A> </LI></UL> <UL class=hide id=mb3> <LI><A href="#" target=_parent>脚本之家</A> </LI> <LI><A href="#" target=_parent>脚本之家</A> </LI> <LI><A href="#" target=_parent>网络营销</A> </LI> <LI><A href="#" target=_parent>网络营销</A> </LI> <LI><A href="#" target=_parent>网络营销</A> </LI> <LI><A href="#" target=_parent>网络营销</A> </LI> <LI><A href="#" target=_parent>网络营销</A> </LI> <LI><A href="#" target=_parent>网页特效</A> </LI></UL> <UL class=hide id=mb4> <LI><A href="#" target=_parent>脚本之家</A> </LI> <LI><A href="#" target=_parent>网页特效</A> </LI> <LI><A href="#" target=_parent>网络营销</A> </LI> <LI><A href="#" target=_parent>网络营销</A> </LI></UL> <UL class=hide id=mb5> <LI><A href="#" target=_parent>脚本之家</A> </LI> <LI><A href="#" target=_parent>服务器租用首页</A> </LI> <LI><A href="#" target=_parent>网络营销</A> </LI> <LI><A href="#" target=_parent>网络营销</A> </LI> <LI><A href="#" target=_parent>超级机房</A> </LI> <LI><A href="#" target=_parent>脚本之家</A> </LI></UL> <UL class=hide id=mb6> <LI><A href="#" target=_parent>脚本之家</A> </LI> <LI><A href="#" target=_parent>脚本下载</A> </LI> <LI><A href="#" target=_parent>脚本之家</A> </LI> <LI><A href="#" target=_parent>脚本之家</A> </LI></UL> <UL class=hide id=mb7> <LI><A href="#" target=_parent>脚本之家</A> </LI> <LI><A href="#" target=_parent>脚本之家</A> </LI> <LI><A href="#" target=_parent>脚本之家</A> </LI> <LI><A href="#" target=_parent>个人建站</A> </LI> <LI><A href="#" target=_parent>门户建站</A> </LI></UL> <UL class=hide id=mb8 style="DISPLAY: none"> <LI><A href="#" target=_parent>脚本之家</A> </LI> <LI><A href="#" target=_parent>网络营销</A> </LI> <LI><A href="#" target=_parent>网络营销</A> </LI></UL> <UL class=hide id=mb9> <LI><A href="#">脚本之家</A> </LI> <LI><A href="#" target=_parent>网络营销</A> </LI> <LI><A href="#" target=_parent>网页特效</A> </LI> <LI><A href="#" target=_parent>网络营销</A> </LI> <LI><A href="#" target=_parent>网络营销</A> </LI></UL> <script> function mmenuURL()//主导航、二级导航显示函数 { var thisURL = document.URL; tmpUPage = thisURL.split( "/" ); thisUPage_s = tmpUPage[ tmpUPage.length-2 ]; thisUPage_s= thisUPage_s.toLowerCase();//小写 //thisUPage=thisUPage.substring(0,4) if(thisUPage_s=="test.hichina.com"||thisUPage_s=="www.net.cn"||thisUPage_s=="www.hichina.com") { getObject("mm1").className="menuhover" getObject("mb1").className = ""; } else if(thisUPage_s=="domain") { getObject("mm2").className="menuhover" getObject("mb2").className = ""; } else if(thisUPage_s=="hosting") { getObject("mm3").className="menuhover" getObject("mb3").className = ""; } else if(thisUPage_s=="mail") { getObject("mm4").className="menuhover" getObject("mb4").className = ""; } else if(thisUPage_s=="solutions"||thisUPage_s=="site"){ getObject("mm5").className="menuhover" getObject("mb5").className = ""; } else if(thisUPage_s=="promotion"){ getObject("mm6").className="menuhover" getObject("mb6").className = ""; } else if(thisUPage_s=="trade"||thisUPage_s=="phonetic"||thisUPage_s=="switchboard"||thisUPage_s=="note"){ getObject("mm7").className="menuhover" getObject("mb7").className = ""; } else if(thisUPage_s=="benefit"){ getObject("mm8").className="menuhover" getObject("mb8").className = ""; } else if(thisUPage_s=="userlogon"||thisUPage_s=="domain_service"||thisUPage_s=="hosting_service"||thisUPage_s=="mail_service"||thisUPage_s=="Payed"||thisUPage_s=="unPayed"||thisUPage_s=="Invoice"||thisUPage_s=="Finance"||thisUPage_s=="RegInfoModify"){ getObject("mm9").className="menuhover" getObject("mb9").className = ""; } else { getObject("mm1").className=""; getObject("mb1").className = ""; } } window.load=mmenuURL() </script> </DIV> </DIV> </body> </html>
希望本文所述對大家的javascript程式設計有所幫助。

如何使用JS和百度地图实现地图平移功能百度地图是一款广泛使用的地图服务平台,在Web开发中经常用于展示地理信息、定位等功能。本文将介绍如何使用JS和百度地图API实现地图平移功能,并提供具体的代码示例。一、准备工作使用百度地图API前,首先需要在百度地图开放平台(http://lbsyun.baidu.com/)上申请一个开发者账号,并创建一个应用。创建完成

如何使用JS和百度地图实现地图热力图功能简介:随着互联网和移动设备的迅速发展,地图成为了一种普遍的应用场景。而热力图作为一种可视化的展示方式,能够帮助我们更直观地了解数据的分布情况。本文将介绍如何使用JS和百度地图API来实现地图热力图的功能,并提供具体的代码示例。准备工作:在开始之前,你需要准备以下事项:一个百度开发者账号,并创建一个应用,获取到相应的AP

js字符串转数组的方法:1、使用“split()”方法,可以根据指定的分隔符将字符串分割成数组元素;2、使用“Array.from()”方法,可以将可迭代对象或类数组对象转换成真正的数组;3、使用for循环遍历,将每个字符依次添加到数组中;4、使用“Array.split()”方法,通过调用“Array.prototype.forEach()”将一个字符串拆分成数组的快捷方式。

如何使用JS和百度地图实现地图多边形绘制功能在现代网页开发中,地图应用已经成为常见的功能之一。而地图上绘制多边形,可以帮助我们将特定区域进行标记,方便用户进行查看和分析。本文将介绍如何使用JS和百度地图API实现地图多边形绘制功能,并提供具体的代码示例。首先,我们需要引入百度地图API。可以利用以下代码在HTML文件中导入百度地图API的JavaScript

js中new操作符做了:1、创建一个空对象,这个新对象将成为函数的实例;2、将新对象的原型链接到构造函数的原型对象,这样新对象就可以访问构造函数原型对象中定义的属性和方法;3、将构造函数的作用域赋给新对象,这样新对象就可以通过this关键字来引用构造函数中的属性和方法;4、执行构造函数中的代码,构造函数中的代码将用于初始化新对象的属性和方法;5、如果构造函数中没有返回等等。

这篇文章主要为大家详细介绍了js实现打字小游戏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。

php在特定情况下可以读js内部的数组。其方法是:1、在JavaScript中,创建一个包含需要传递给PHP的数组的变量;2、使用Ajax技术将该数组发送给PHP脚本。可以使用原生的JavaScript代码或者使用基于Ajax的JavaScript库如jQuery等;3、在PHP脚本中,接收传递过来的数组数据,并进行相应的处理即可。

js全称JavaScript,是一种具有函数优先的轻量级,直译式、解释型或即时编译型的高级编程语言,是一种属于网络的高级脚本语言;JavaScript基于原型编程、多范式的动态脚本语言,并且支持面向对象、命令式和声明式,如函数式编程。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

禪工作室 13.0.1
強大的PHP整合開發環境