ITPub博客

首页 > 应用开发 > IT综合 > xp风格菜单 (转)

xp风格菜单 (转)

原创 IT综合 作者:worldblog 时间:2007-12-12 10:15:03 0 删除 编辑
xp风格菜单 (转)[@more@]

网易的个人主页收费了,顺便把以前写的一些东西贴出来,或许可以用用。

xp风格菜单

context.js

<!--
/**
 *@context menu with xp style
 *@author: LiXinGang  Mailto:avlee@163.com">avlee@163.com 2002.3.25
 *@version v1.0
 */

// menu object
function contextMenu()
{
 this.items  = new Array();
 
 this.addItem = function (item)
 {
 this.items[this.items.length] = item;
 }

 this.show = function (oDoc)
 {
 var strShow = "";
 var i;
 
 strShow = "

n";
 oDoc.write(strShow);
 }
}

// menu Item object
function contextItem(text, icon, cmd, type)
{
 this.text = text ? text : "";
 this.icon = icon ? icon : "";
 this.cmd = cmd ? cmd : "";
 this.type = type ? type : "menu";
 
 this.show = function (oDoc)
 {
 var strShow = "";
 
 if(this.type == "menu")
 {
 strShow += " strShow += "onmouseover="changeStyle(this, 'on');" ";
 strShow += "onmouseout="changeStyle(this, 'out');" ";
 strShow += "onclick="";
 strShow += this.cmd;
 strShow += "">";
 strShow += "";
 if (this.icon == "")
 strShow += " ";
 else {
 strShow += " strShow += this.icon;
 strShow += "" width="16" height="16" style="POSITION: relative">";
 }
 strShow += "";
 strShow += this.text;
 strShow += " ";
 }
 else if (this.type == "separator")
 {
 strShow += " ";
 strShow += "


";
 }
 
 oDoc.write(strShow);
 }
}

function changeStyle(obj, cmd)

 if(obj) try {
 var imgObj = obj.children(0).children(0);
 
 if(cmd == 'on') {
 obj.children(0).className = "ltdfocus";
 obj.children(1).className = "mtdfocus";
 obj.children(2).className = "rtdfocus";
 if(imgObj)
 {
 if(imgObj.tagName.toUpperCase() == "IMG")
 {
 imgObj.style.left = "-1px";
 imgObj.style.top = "-1px";
 }
 }
 }
 else if(cmd == 'out') {
 obj.children(0).className = "ltdexit";
 obj.children(1).className = "mtdexit";
 obj.children(2).className = "rtdexit";
 if(imgObj)
 {
 if(imgObj.tagName.toUpperCase() == "IMG")
 {
 imgObj.style.left = "0px";
 imgObj.style.top = "0px";
 }
 }
 }
 }
 catch (e) {}
}

function showMenu()
{
 var x, y, w, h, ox, oy;
 
 x = event.clientX;
 y = event.clientY;
 
 var obj = document.getElementById("rightmenu");
 if (obj == null)
 return true;
 
 ox = document.body.clientWidth;
 oy = document.body.clientHeight;
 if(x > ox || y > oy)
 return false;
 w = obj.offsetWidth;
 h = obj.offsetHeight;
 if((x + w) > ox)
 x = x - w;
 if((y + h) > oy)
 y = y - h;
 
 obj.style.posLeft = x + document.body.scrollLeft;
 obj.style.posTop = y + document.body.scrollTop;
 obj.style.visibility = "visible";
 
 return false;
}
function hideMenu()
{
 if(event.button == 0)
 {
 var obj = document.getElementById("rightmenu");
 if (obj == null)
 return true;
 obj.style.visibility = "hidden";
 obj.style.posLeft = 0;
 obj.style.posTop = 0;
 }
}

function writeStyle()
{
 var strStyle = "";
 
 strStyle += "";
 
 document.write(strStyle);
}

function makeMenu()
{
 var myMenu, item;
 
 var homepage_cmd = "this.style.behavior='url(#default#homepage)';this.setHomePage('http://gamethinking.yeah.NET/'); return false;";
 var favorate_cmd = "window.external.addFavorite('http://gamethinking.yeah.net/','游戏思想'); return false;";
 var viewcode_cmd = "window.location = 'view-source:' + window.location.href";
 
 myMenu = new contextMenu();
 
 item = new contextItem("返回主页", "images/main.gif", "top.location='http://gamethinking.yeah.net/';", "menu");
 myMenu.addItem(item);
 
 item = new contextItem("设为主页", "images/myhome.gif", homepage_cmd, "menu");
 myMenu.addItem(item);
 
 item = new contextItem("添加到收藏夹", "images/fav_add.gif", favorate_cmd, "menu");
 myMenu.addItem(item);
 
 item = new contextItem("联系作者", "images/mail.gif", "location.href='mailto:avlee@163.com'", "menu");
 myMenu.addItem(item);
 
 item = new contextItem("", "", "", "separator");
 myMenu.addItem(item);
 
 item = new contextItem("察看源码", "images/edit.gif", viewcode_cmd, "menu");
 myMenu.addItem(item);
 
 myMenu.show(this.document);

 delete item;
 delete myMenu;
}

function toggleMenu(isEnable)
{
 if(isEnable)
 document.oncontextmenu = showMenu;
 else
 document.oncontextmenu = new function() {return true;};
}

writeStyle();
makeMenu();
document.onclick = hideMenu;
document.oncontextmenu = showMenu;
file://-->

menutest.htm










 
 
 

 

 xp风格的右键菜单

 欢迎使用
 

 

 

关闭右键菜单


 



来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-991677/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    6241
  • 访问量
    2410110