CSS+DIV下拉菜单

lovefm105 2007-05-22 09:42:05
这是JS文件
//Chrome Drop Down Menu- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Last updated: June 14th, 06'

var cssdropdown={
disappeardelay: 250, //set delay in miliseconds before menu disappears onmouseout
disablemenuclick: true, //when user clicks on a menu item with a drop down menu, disable menu item's link?
enableswipe: 1, //enable swipe effect? 1 for yes, 0 for no

//No need to edit beyond here////////////////////////
dropmenuobj: null, ie: document.all, firefox: document.getElementById&&!document.all, swipetimer: undefined, bottomclip:0,

getposOffset:function(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
},

swipeeffect:function(){
if (this.bottomclip<parseInt(this.dropmenuobj.offsetHeight)){
this.bottomclip+=10+(this.bottomclip/10) //unclip drop down menu visibility gradually
this.dropmenuobj.style.clip="rect(0 auto "+this.bottomclip+"px 0)"
}
else
return
this.swipetimer=setTimeout("cssdropdown.swipeeffect()", 10)
},

showhide:function(obj, e){
if (this.ie || this.firefox)
this.dropmenuobj.style.left=this.dropmenuobj.style.top="-500px"
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover"){
if (this.enableswipe==1){
if (typeof this.swipetimer!="undefined")
clearTimeout(this.swipetimer)
obj.clip="rect(0 auto 0 0)" //hide menu via clipping
this.bottomclip=0
this.swipeeffect()
}
obj.visibility="visible"
}
else if (e.type=="click")
obj.visibility="hidden"
},

iecompattest:function(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
},

clearbrowseredge:function(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=this.ie && !window.opera? this.iecompattest().scrollLeft+this.iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetWidth
if (windowedge-this.dropmenuobj.x < this.dropmenuobj.contentmeasure) //move menu to the left?
edgeoffset=this.dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=this.ie && !window.opera? this.iecompattest().scrollTop : window.pageYOffset
var windowedge=this.ie && !window.opera? this.iecompattest().scrollTop+this.iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetHeight
if (windowedge-this.dropmenuobj.y < this.dropmenuobj.contentmeasure){ //move up?
edgeoffset=this.dropmenuobj.contentmeasure+obj.offsetHeight
if ((this.dropmenuobj.y-topedge)<this.dropmenuobj.contentmeasure) //up no good either?
edgeoffset=this.dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
},

dropit:function(obj, e, dropmenuID){
if (this.dropmenuobj!=null) //hide previous menu
this.dropmenuobj.style.visibility="hidden" //hide menu
this.clearhidemenu()
if (this.ie||this.firefox){
obj.onmouseout=function(){cssdropdown.delayhidemenu()}
obj.onclick=function(){return !cssdropdown.disablemenuclick} //disable main menu item link onclick?
this.dropmenuobj=document.getElementById(dropmenuID)
this.dropmenuobj.onmouseover=function(){cssdropdown.clearhidemenu()}
this.dropmenuobj.onmouseout=function(){cssdropdown.dynamichide(e)}
this.dropmenuobj.onclick=function(){cssdropdown.delayhidemenu()}
this.showhide(this.dropmenuobj.style, e)
this.dropmenuobj.x=this.getposOffset(obj, "left")
this.dropmenuobj.y=this.getposOffset(obj, "top")
this.dropmenuobj.style.left=this.dropmenuobj.x-this.clearbrowseredge(obj, "rightedge")+"px"
this.dropmenuobj.style.top=this.dropmenuobj.y-this.clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+1+"px"
}
},

contains_firefox:function(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
},

dynamichide:function(e){
var evtobj=window.event? window.event : e
if (this.ie&&!this.dropmenuobj.contains(evtobj.toElement))
this.delayhidemenu()
else if (this.firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
this.delayhidemenu()
},

delayhidemenu:function(){
this.delayhide=setTimeout("cssdropdown.dropmenuobj.style.visibility='hidden'",this.disappeardelay) //hide menu
},

clearhidemenu:function(){
if (this.delayhide!="undefined")
clearTimeout(this.delayhide)
},

startchrome:function(){
for (var ids=0; ids<arguments.length; ids++){
var menuitems=document.getElementById(arguments[ids]).getElementsByTagName("a")
for (var i=0; i<menuitems.length; i++){
if (menuitems[i].getAttribute("rel")){
var relvalue=menuitems[i].getAttribute("rel")
menuitems[i].onmouseover=function(e){
var event=typeof e!="undefined"? e : window.event
cssdropdown.dropit(this,event,this.getAttribute("rel"))
}
}
}
}
}

}
...全文
1141 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovefm105 2007-05-22
  • 打赏
  • 举报
回复
没有好的解决的办法吗???
Ischema 2007-05-22
  • 打赏
  • 举报
回复
javascript跨浏览器兼容性问题
开发者的噩梦!
lovefm105 2007-05-22
  • 打赏
  • 举报
回复
为什么这个下拉菜单在遨游下面没法显示呢??
在IE下没问题~~一切正常
lovefm105 2007-05-22
  • 打赏
  • 举报
回复
<!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" lang="gb2312" xml:lang="gb2312">
<head>
<title>众志电子DIV版本</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript" src="chrome.js">
</script>
<style type="text/css">
<!--
.chromestyle {width:760px; background-color:#165AB3; height:25px; vertical-align:middle; line-height:25px;
/*font-weight:bold;*/}

.chromestyle ul{text-align:left;}

.chromestyle ul li { display:inline;} <!--让LI没有黑点横向排列-->

.chromestyle ul li a {
color:#494949;
padding:4px 7px;
margin:0;
text-decoration:none;
border-right:1px solid #DADADA;
}


.chromestyle ul li a[rel]:after{
content:"v";
}

.chromestyle:after{

content:".";
display:block;
height:0;
clear:both;
visibility:hidden;
}
.dropmenudiv {
position:absolute;
top:0;
border:1px solid #165AB3; /*边框*/
border-bottom-width:0;
font:normal 12px Verdana;
line-height:18px;
z-index:100;
background-color:#5293d1;
width:100px;
visibility:hidden;
filter:progid:DXImageTransform.Microsoft.Shadow(color=#CACACA,direction=135,strength=4);
}

.dropmenudiv a{
width:auto;
display:block;
text-align:3x;
padding:2px 0;
border-bottom:1px solid #165AB3;/*设置对象下边框的样式*/
text-decoration:none;
font-weight:bold;
color:#FFFFFF;
}

* html .dropmenudiv a{
width:100%;
}

.dropmenudiv a:hover
{
background-color:#1d7fdb;
}
body {
font-size: 12px;
text-decoration: none;
margin: 0px;
text-align:center;
}




a:link {
color: #FFFFFF;
text-decoration: none;
}

a:visited {
color: #FFFFFF;
text-decoration: none;
}

a:hover {
text-decoration: none;
color:#FFFF00
}

a:active {
color: #FFFFFF;
text-decoration: none;

}

a.hidden {
color: #FFFFFF;
}

*{margin:0;padding:0;}


-->
</style>
<link href="index.css" rel="stylesheet" type="text/css" />
</head>

<body>

<!-- 主菜单 -->
<div id="chromemenu" class="chromestyle">
<ul>
<li><a href="#">      首 页 | </a></li>
<li><a href="#" rel="dropmenu1">  新闻中心   | </a></li>
<li><a href="#" rel="dropmenu2">  产品方案   | </a></li>
<li><a href="#" rel="dropmenu3">  服务支持   | </a></li>
<li><a href="#" rel="dropmenu3">  人才招聘   | </a></li>
<li><a href="#" rel="dropmenu3">  关于众志   | </a></li>
</ul>
</div>

<!-- 第一连菜单 -->
<div id="dropmenu1" class="dropmenudiv">
<a href="#">Dynamic Drive</a>
<a href="#">CSS Drive</a>
<a href="#">JavaScript</a>
<a href="#">Coding Forums</a></div>

<!-- 第二连菜单 -->
<div id="dropmenu2" style="width:100px;" class="dropmenudiv">
<a href="#">CNN</a>
<a href="#">MSNBC</a>
<a href="#">BBC News</a>
<a href="#">VCS</a>
<a href="#">Menus</a>
</div>


<!-- 第三连菜单 -->
<div id="dropmenu3" style="width:100px;" class="dropmenudiv">
<a href="#">Google</a>
<a href="#">Yahoo</a>
<a href="#">Sohu</a>
<a href="#">Tencent</a></div>


<script type="text/javascript">
cssdropdown.startchrome("chromemenu")

</script>

</body>
</html>

这是主程序--菜单

61,110

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧