MenuG5总结
MenuG5是一个使用Javascript来生成菜单的组件。支持页面菜单和框架菜单,解决了在实际开发过程中,框架中菜单被遮挡的问题。
1 下载
下载地址:http://www.yxscripts.com/menuG5/
2 项目中如何使用
下载到本地后,把压缩包解压,压缩包中的目录结构如下:
.css
.examples
.faq
.script
.index.html
一般情况下,只要把其中的script和css两个目录引入到项目中即可。
需要注意的是,在script下有多个JS,这些JS是根据不同浏览器和是否支持框架来区分的。在文件名字中有“FS”是支持框架的,而不带“FS”是不支持框架的,在引用的时候需要注意。
3 菜单生成语句
- 添加一个新菜单
addMenu("menu-name", "top-menu-name");
- 添加一个链接菜单
addLink("top/sub-menu-name", "item text", "item msg", "URL", "group-id");
addLink("top/sub-menu-name", "item text", "item msg", "URL", "group-id", "target-frame-name");
- 添加一个命令菜单,命令使用JS语句
addCommand("top/sub-menu-name", "item text", "item msg", "JS-codes", "group-id");
addLink("top/sub-menu-name", "item text", "item msg", "javascript:JS-codes", "group-id");
- 添加一个子菜单
addSubMenu("top/sub-menu-name", "item text", "item msg", "URL", "sub-menu-name", "group-id");
addSubMenu("top/sub-menu-name", "item text", "item msg", "URL", "sub-menu-name", "group-id", "target-frame-name");
- 添加一个信息项
addInfo("top/sub-menu-name", "info content", "group-id");
- 添加菜单中的分隔符
addSeparator("top/sub-menu-name", "group-id");
4 菜单样式
菜单的颜色、形状、位置都是通过CSS进行控制的。CSS的定义和普通的CSS定义是一样的。
5 把样式加入到菜单样式中
以下语句请参照:
http://www.yxscripts.com/menuG5/faq/spec.html#style,
全英文的,需要仔细阅读。
addStylePad("pad","item-offset:-1; offset-top:1;");
addStylePad("padSub","item-offset:-1; offset-top:6; offset-left:-6;");
addStyleItem("itemTop","css:itemTopOff, itemTopOn;");
addStyleItem("itemSub","css:itemSubOff, itemSubOn;");
addStyleFont("fontTop","css:fontOff, fontOn;");
addStyleFont("fontSub","css:fontOff, fontOn;");
addStyleTag("tag","css:tagOff, tagOn;");
上面的这些语句可以自己根据需求来写,也可以参照下载的文件中Examples/Menu目录下的JS文件,可以直接引用,也可以在此基础上修改。
6 把样式应用在具体的菜单项上
样式应用在菜单项上,并不是对每个菜单项单独的设置样式,而是根据菜单项的类别应用样式。比如:菜单应用一个样式;子菜单应用一个样式;一个组应用一个样式。
addStyleMenu("menu","pad","itemTop","fontTop","","","");
addStyleMenu("sub","pad","itemSub","fontSub","tag","","");
addStyleMenu("sub2","padSub","itemSub","fontSub","","","");
addStyleGroup("group","menu","demo-top");
addStyleGroup("group","sub","tool-sub","game-sub","forum-sub");
addStyleGroup("group","sub2","menu-sub");
7 初始加载菜单
addInstance("Demo","Demo","position:relative holder; menu-form:bar; align:center; style:group;");
相关说明请阅读:
http://www.yxscripts.com/menuG5/faq/spec.html#instance
8 完整的一个菜单
<%@ page language="java"import="java.util.*"pageEncoding="UTF-8"%>
<%
String path=request.getContextPath();
%>
<!DOCTYPEHTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<metahttp-equiv="pragma"content="no-cache">
<metahttp-equiv="cache-control"content="no-cache">
<metahttp-equiv="expires"content="0">
<metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
<metahttp-equiv="description"content="This is my page">
<linkrel="stylesheet"type="text/css"href="<%=path%>/css/menuG5.css">
<scripttype="text/javascript"src="<%=path%>/script/menuG5LoaderX.js"></script>
<styletype="text/css">
.itemTopOff {width:130px;padding:1px;border:1px solid #000000;text-align:center;background-color:#ccefcc; }
.itemTopOn {cursor:default;width:130px;padding:1px;border:1px solid #000000;text-align:center;background-color:#333333; }
.itemSubOff {width:115px;padding:1px 6px 1px 11px;border:1px solid #000000;text-align:left;background-color:#cccccc; }
.itemSubOn {cursor:default;width:115px;padding:1px 6px 1px 11px;border:1px solid #000000;text-align:left;background-color:#333333; }
.fontOff {font-family:verdana;font-size:10pt;color:#000000; }
.fontOn {font-family:verdana;font-size:10pt;color:#ffffff; }
.tagOff {width:8px;height:13px;float:right;background:url("images/tagRN.gif") no-repeat bottom; }
.tagOn {width:8px;height:13px;float:right;background:url("images/tagRH.gif") no-repeat bottom; }
</style>
</head>
<bodyοnlοad="showMenu('Demo')">
<tablealign="center"border="1"cellpadding="0"cellspacing="5">
<tr>
<tdid="holder"></td>
</tr>
<tr>
<td></td>
</tr>
</table>
</body>
</html>
<scripttype="text/javascript"language="javascript">
initMenu();
function initMenu()
{
addMenu("Demo","demo-top");
addLink("demo-top","Home","","index.jsp","");
addSubMenu("demo-top","文件..","","","fileMenu","");
addLink("fileMenu","新文件","","index.jsp","g1");
addLink("fileMenu","打开..","","index.jsp","g1");
addSeparator("fileMenu","g1");
addCommand("fileMenu","保存","保存文件","alert('文件名称?');","");
addCommand("fileMenu","另存为 ..","文件另存为","alert('是否真的要另存?')","");
addSubMenu("demo-top","编辑..","","","editMenu","");
addLink("editMenu","查找","","index.jsp","");
addLink("editMenu","替换","","index.jsp","");
endMenu();
addStylePad("pad","item-offset:-1; offset-top:1;");
addStylePad("padSub","item-offset:-1; offset-top:6; offset-left:-6;");
addStyleItem("itemTop","css:itemTopOff, itemTopOn;");
addStyleItem("itemSub","css:itemSubOff, itemSubOn;");
addStyleFont("fontTop","css:fontOff, fontOn;");
addStyleFont("fontSub","css:fontOff, fontOn;");
addStyleTag("tag","css:tagOff, tagOn;");
addStyleMenu("menu","pad","itemTop","fontTop","","","");
addStyleMenu("sub","pad","itemSub","fontSub","tag","","");
addStyleMenu("sub2","padSub","itemSub","fontSub","","","");
addStyleGroup("group","menu","demo-top");
addStyleGroup("group","sub","tool-sub","game-sub","forum-sub");
addStyleGroup("group","sub2","menu-sub");
addInstance("Demo","Demo","position:relative holder; menu-form:bar; align:center; style:group;");
}
</script>