本文实例讲述了jQuery实现自定义右键菜单的树状菜单效果。分享给大家供大家参考。具体如下:
这是一款基于jQuery的自定义右键菜单,在树状结构的子节点(下级没有节点)上单击右键才会弹出自定义菜单,而且菜单是自动根据鼠标位置来定位的。当鼠标在菜单以外的任意空白处单击一下后会自动消失。这里想特别说明一点所谓的“菜单以外”,可以有两种解剖方式——1、除了鼠标在菜单区域内的所有位置;2、如下图所示的A、B、C、D四个区域。显然用第一种方法来剖析会更简单直接一点。源码中的!IsInArea就表示此方法。
运行效果截图如下:
在线演示地址如下:
http://demo.jb51.net/js/2015/jquery-zdy-right-button-menu-style-codes/
具体代码如下:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>jQuery自定义右键菜单</title>
<style type="text/css">
body {
font-size: 12px;
margin: 0px;
padding: 0px;
}
form,div,ul,li {
margin: 0px;
padding: 0px;
list-style-type: none;
overflow: hidden;
}
h1,h2,h3,h4,h5 {
font-size: 12px;
margin: 0px;
padding: 0px;
}
a {
text-decoration: none;
}
.layout {
width: 993px;
clear: both;
margin-right: auto;
margin-left: auto;
border-top-width: 0px;
border-right-width: 4px;
border-bottom-width: 0px;
border-left-width: 4px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: #000000;
border-right-color: #000000;
border-bottom-color: #000000;
border-left-color: #000000;
overflow: hidden;
}
.layout2 {
width: 942px;
margin-right: auto;
margin-left: auto;
}
.Content {
background-color: #376285;
}
.contentBg {
background-color: #173043;
}
div, ul, li {
margin: 0px;
padding: 0px;
list-style-type: none;
}
body {
background-color: #FFFFFF;
font-size: 12px;
margin: 0px;
padding: 0px;
}
#TreeList {
background-color: #FFFFFF;
margin-top: 6px;
margin-right: 9px;
margin-bottom: 6px;
margin-left: 9px;
border: 1px solid #5d7b96;
padding-bottom: 6px;
padding-left: 6px;
}
#TreeList .mouseOver {
background-color: #FAF3E2;
}
#TreeList .ParentNode {
line-height: 21px;
height: 21px;
margin-top: 2px;
clear: both;
}
#TreeList .ChildNode {
background-image: url(images/Sys_ModuleIcos.png);
background-position: 15px -58px;
padding-left: 39px;
line-height: 21px;
background-repeat: no-repeat;
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 1px;
border-left-width: 0px;
border-top-style: dashed;
border-right-style: dashed;
border-bottom-style: dashed;
border-left-style: dashed;
border-top-color: #aabdce;
border-right-color: #aabdce;
border-bottom-color: #aabdce;
border-left-color: #aabdce;
cursor: default;
clear: both;
height: 21px;
color: #314f6a;
}
#TreeList .title {
float: left;
}
#TreeList .input {
font-size: 12px;
line-height: 18px;
color: #FFF;
height: 16px;
background-color: #3F6B8F;
width: 120px;
text-align: center;
margin-top: 1px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: #1F3547;
border-right-color: #FFF;
border-bottom-color: #FFF;
border-left-color: #1F3547;
float: left;
}
#TreeList .editBT {
float: left;
overflow: visible;
}
#TreeList .editBT .ok {
background-image: url(images/Sys_ModuleIcos.png);
background-repeat: no-repeat;
background-position: 0px -89px;
height: 13px;
width: 12px;
float: left;
margin-left: 3px;
padding: 0px;
margin-top: 3px;
cursor: pointer;
}
#TreeList .editBT .cannel {
background-image: url(images/Sys_ModuleIcos.png);
background-repeat: no-repeat;
background-position: 0px -120px;
float: left;
height: 13px;
width: 12px;
margin-left: 3px;
padding: 0px;
margin-top: 3px;
cursor: pointer;
}
#TreeList .editArea {
float: right;
color: #C3C3C3;
cursor: pointer;
margin-right: 6px;
}
#TreeList .editArea span {
margin: 2px;
}
#TreeList .editArea .mouseOver {
color: #BD4B00;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: #C9925A;
border-right-color: #E6CFBB;
border-bottom-color: #E6CFBB;
border-left-color: #C9925A;
background-color: #FFFFFF;
margin: 0px;
padding: 1px;
}
#TreeList .ParentNode .title {
color: #314f6a;
cursor: pointer;
background-image: url(images/Sys_ModuleIcos.png);
background-repeat: no-repeat;
padding-left: 39px;
}
#TreeList .ParentNode.show .title {
font-weight: bold;
background-position: 3px -27px;
}
#TreeList .ParentNode.hidden .title {
background-position: 3px 4px;
}
#TreeList .ParentNode .editArea {
color: #999;
}
#TreeList .ParentNode.show {
background-color: #d1dfeb;
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: #5d7b96;
border-right-color: #5d7b96;
border-bottom-color: #5d7b96;
border-left-color: #5d7b96;
}
#TreeList .ParentNode.hidden {
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 1px;
border-left-width: 0px;
border-top-style: dashed;
border-right-style: dashed;
border-bottom-style: dashed;
border-left-style: dashed;
border-top-color: #aabdce;
border-right-color: #aabdce;
border-bottom-color: #aabdce;
border-left-color: #aabdce;
}
#TreeList .Row {
clear: both;
margin-left: 24px;
background-image: url(images/Sys_ModuleIcos2.png);
background-repeat: repeat-y;
background-position: 7px 0px;
}
h1 {
font-size: 12px;
line-height: 24px;
color: #FFF;
background-color: #396384;
text-align: center;
margin: 0px;
padding: 0px;
}
#OpLimits_Menu {
position: absolute;
width: 70px;
cursor: default;
filter: Alpha(Opacity=90);
}
#OpLimits_Menu ul {
background-color: #d5effc;
border: 1px solid #3e8dad;
}
#OpLimits_Menu ul li {
line-height: 18px;
color: #496D81;
text-align: center;
letter-spacing: 0.3em;
height: 18px;
cursor: pointer;
}
#OpLimits_Menu ul .onmouse {
background-image: url(images/bt1.gif);
background-repeat: repeat-x;
color: #324A58;
}
</style>
<script type="text/javascript" src="/UploadFiles/2021-04-02/jquery-1.6.2.min.js">
希望本文所述对大家的jquery程序设计有所帮助。
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“jQuery实现自定义右键菜单的树状菜单效果”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新动态
2025年10月25日
2025年10月25日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]
