右键菜单的制作!

王朝other·作者佚名  2006-12-16
窄屏简体版  字體: |||超大  

MENU.JS// 菜单的HTML代码

var strMenu = "

onMouseover=\"highlight()\" onMouseout=\"lowlight()\">"

strMenu += "

刷新"

strMenu += "

关闭"

strMenu += "

"

strMenu += "

http://fj126.net);\"

>设为首页"

strMenu += "

.::蓝雨设计网::.)\">加入收藏"

strMenu += "

"

// 判断客户端浏览器

function ie() {

if (navigator.appName=="Microsoft Internet Explorer") {

return true;

} else {

return false;

}}

// 显示菜单

function showmenu(){

if (ie()){

// 找出鼠标在窗口中的位置

var rightedge=document.body.clientWidth-event.clientX

var bottomedge=document.body.clientHeight-event.clientY

// 如果横向的距离小于菜单的宽度

if (rightedge

// 将菜单向左移动到适当的位置

menu.style.left=document.body.scrollLeft+event.clientX-menu.offsetWidth

else

// 否则,就在该位置显示菜单

menu.style.left=document.body.scrollLeft+event.clientX

// 与上面道理相同,判断纵向的位置

if (bottomedge

menu.style.top=document.body.scrollTop+event.clientY-menu.offsetHeight

else

menu.style.top=document.body.scrollTop+event.clientY

menu.style.visibility="visible"

}

return false

}

// 隐藏菜单

function hidemenu(){

if (ie()) menu.style.visibility="hidden"

}

// 菜单项获得焦点时加亮显示

function highlight(){

if (event.srcElement.className=="menuitems"){

event.srcElement.style.backgroundColor="highlight"

event.srcElement.style.color="highlighttext"

}}

// 菜单项失去焦点

function lowlight(){

if (event.srcElement.className=="menuitems"){

event.srcElement.style.backgroundColor=""

event.srcElement.style.color="menutext"

}}

if (ie()) document.write (strMenu);

document.oncontextmenu= showmenu

document.body.onclick= hidemenu

MENU.CSS

.clsMenu {

cursor: default;

color: menutext;

position: absolute;

width: 120px;

background-color: menu;

border: 1 solid buttonface;

visibility:hidden;

border: 2 outset buttonhighlight;

}

.menuitems{

font-size: 12px;

color: #000000;

padding-left:20px;

padding-right:10px;

line-height: 20px

}

INDEX.HTM把加入HEAD区

加入BODY区

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航