分析了一下代码:
首先要有mm_menu.js文件,似乎是macromedia公司写的,
* mm_menu 20MAR2002 Version 6.0
* Andy Finnell, March 2002
* Copyright (c) 2000-2002 Macromedia, Inc.
不知道是不是dreamweaver中内含的文件。
下载
http://www-2.zju.edu.cn/mm_menu.js
然后,在需要的页面的<head>之间,调用文件中的
function mmLoadMenus() {
if (window.mm_menu_0423132603_0) return;
window.mm_menu_0423132603_0 = new Menu("root",97,26,"",14,"#000000","#FFFFFF","#ffffff","#777777","left","middle",8,-1,1000,-5,7,true,true,true,0,true,true);
mm_menu_0423132603_0.addMenuItem("领 导 致 辞","window.open('xqzl/ldzc.htm', '_self');");
mm_menu_0423132603_0.addMenuItem("学 校 概 况","window.open('xqzl/xygk/xygk.htm', '_self');");
mm_menu_0423132603_0.addMenuItem("院 系 设 置","window.open('xqzl/yxsz.htm', '_self');");
mm_menu_0423132603_0.addMenuItem("党 政 机 构","window.open('xqzl/dzjg/dzjg.htm', '_self');");
mm_menu_0423132603_0.addMenuItem("学 校 标 志","window.open('xqzl/biaozhi/bz.htm', '_self');");
mm_menu_0423132603_0.addMenuItem("历 史 沿 革","window.open('xqzl/lsyg/lsyg.htm', '_self');");
mm_menu_0423132603_0.addMenuItem("历 任 校 长","window.open('xqzl/lrxz/lrxz.htm', '_self');");
mm_menu_0423132603_0.addMenuItem("校 区 一 览","window.open('xqzl/xqyl/xqly.htm', '_self');");
mm_menu_0423132603_0.addMenuItem("校 园 风 景","window.open('xqzl/fj/fj.htm', '_self');");
mm_menu_0423132603_0.addMenuItem("统 计 资 料","window.open('xqzl/tj/tj.htm', '_self');");
mm_menu_0423132603_0.addMenuItem("浙 大 图 库","window.open('http://www-2.zju.edu.cn/~piclib/', '_blank');");
mm_menu_0423132603_0.addMenuItem("大 事 记","window.open('xqzl/dsj/dsj4.htm', '_self');");
mm_menu_0423132603_0.hideOnMouseOut=true;
mm_menu_0423132603_0.bgColor='#ffffff';
mm_menu_0423132603_0.menuBorder=1;
mm_menu_0423132603_0.menuLiteBgColor='#FFFFFF';
mm_menu_0423132603_0.menuBorderBgColor='#999999';
window.mm_menu_0423205435_0 = new Menu("root",115,26,"",14,"#000000","#FFFFFF","#ffffff","#777777","left","middle",8,-1,1000,-5,7,true,true,true,0,true,true);
mm_menu_0423205435_0.addMenuItem("研 究 生 教 育","window.open('rcpy/yjsjy/yjsjy.htm', '_self');");
mm_menu_0423205435_0.addMenuItem("本 科 生 教 育","window.open('rcpy/bksjy/bksjy.htm', '_self');");
mm_menu_0423205435_0.addMenuItem("留 学 生 教 育","window.open('gjjl/gjjy.htm', '_self');");
mm_menu_0423205435_0.addMenuItem("成 人 教 育","window.open('http://www.cj.zju.edu.cn/', '_blank');");
mm_menu_0423205435_0.addMenuItem("远 程 教 育","window.open('http://www.zjuyc.com/index.jsp', '_blank');");
mm_menu_0423205435_0.addMenuItem("师 资 培 训","window.open('rcpy/szpx/sz.htm', '_self');");
mm_menu_0423205435_0.addMenuItem("学 科 基 地","window.open('rcpy/xkjd.htm', '_self');");
mm_menu_0423205435_0.hideOnMouseOut=true;
mm_menu_0423205435_0.bgColor='#ffffff';
mm_menu_0423205435_0.menuBorder=1;
mm_menu_0423205435_0.menuLiteBgColor='#FFFFFF';
mm_menu_0423205435_0.menuBorderBgColor='#999999';
……
……
……
}//mmLoadMenus()结束,主要用来生成menu对象,每个对象对应一个menu块
例如:
window.mm_menu_0423132603_0 = new Menu("root",97,26,"",14,"#000000","#FFFFFF","#ffffff","#777777","left","middle",8,-1,1000,-5,7,true,true,true,0,true,true);
注意“mm_menu_0423132603_0”的数字用来区分不同的menu块,其后的97,26代表弹出munu的宽和高 14代表字号
加入,一些必要的函数
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
</SCRIPT>
当然不要忘记
<SCRIPT language=JavaScript src="inc/mm_menu.js"></SCRIPT>
在body中加入<SCRIPT language=JavaScript1.2>mmLoadMenus();</SCRIPT>
然后就可以开始我们激动人心的调用了!
格式如下:
<TD
onmouseover="MM_swapImage('Image1',','images/on_1.jpg',1)"
onmouseout=MM_swapImgRestore()><SPAN class=div_gui id=gui
ondblclick="MM_showMenu(window.mm_menu_0423132603_0,134,0,null,'Image1')"
onmouseover="MM_showMenu(window.mm_menu_0423132603_0,134,0,null,'Image1')"
style="PADDING-LEFT: 24px; Z-INDEX: 1; PADDING-TOP: 16px; POSITION: absolute"
onclick="MM_showMenu(window.mm_menu_0423132603_0,134,0,null,'Image1')">学院概况</SPAN>
<FONT
ondblclick="MM_showMenu(window.mm_menu_0423132603_0,134,0,null,'Image1')"
onmouseover="MM_showMenu(window.mm_menu_0423132603_0,134,0,null,'Image1')"
onclick="MM_showMenu(window.mm_menu_0423132603_0,134,0,null,'Image1')"
onmouseout=MM_startTimeout();><IMG id=Image1 height=49
src="images/1.jpg" width=134 border=0
name=Image1></FONT></TD>
这就是调用一个menu块的代码
其中:
SPAN class=div_gui 的样式需要在css中单独定义
Image1用来表示本menu块
MM_swapImage是显示mouseon后的图片
style="PADDING-LEFT: 24px; Z-INDEX: 1; PADDING-TOP: 16px; POSITION: absolute"
中可以用PADDING-LEFT和PADDING-TOP的值控制文字的位置
ondblclick="MM_showMenu(window.mm_menu_0423132603_0,134,0,null,'Image1')"
中的0用来控制弹出菜单的位置0为平齐,负值为向上移动的位置,正值向下。
好了,这些数据就可以让我应用这个漂亮的menu了!