jQuery自定义右键菜单
首先看下效果,效果在最下面:
代码:
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(/jscss/demoimg/201205/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(/jscss/demoimg/201205/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(/jscss/demoimg/201205/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(/jscss/demoimg/201205/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(/jscss/demoimg/201205/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(/jscss/demoimg/201205/bt1.gif);
background-repeat: repeat-x;
color: #324A58;
}
<div id="TreeList">
<div class="ParentNode show">
<div class="title">title</div>
</div>
<div class="Row">
<div class="ChildNode">
<div class="title">这是一个li</div>
</div>
<div class="ChildNode">
<div class="title">这是一个li</div>
</div>
<div class="ChildNode">
<div class="title">这是一个li</div>
</div>
<div class="ChildNode">
<div class="title">这是一个li</div>
</div>
<div class="ChildNode">
<div class="title">这是一个li</div>
</div>
</div>
</div> <div id="OpLimits_Menu" style="display:none">
<h1>权限设置</h1>
<ul>
<li value="1">查看</li>
<li value="2">添加</li>
<li value="3">修改</li>
<li value="4">删除</li>
</ul>
</div>
js:
$(function(){
/*首先禁用需要操作区域的右键功能*/
$("#TreeList").on("contextmenu", function (e) {
var pointX = e.pageX;
//这里可以得到鼠标Y坐标
var pointY = e.pageY;
var $div = $("div#OpLimits_Menu"); // 右击自定义div
$div.show().css({ "left": pointX, "top": pointY });
return false;
})
/*鼠标右键事件判定 e.which 1 = 鼠标左键 left; 2 = 鼠标中键; 3 = 鼠标右键*/
var $child = $("#TreeList").find("div.ChildNode");
$(document).on("mousedown", function (e) {
var $div = $("div#OpLimits_Menu"); // 右击自定义div
if (e.which != 3) { // 判断是右击事件执行if里面的操作
$div.hide()//
}
})
这就是最终的效果:
权限设置
- 查看
- 添加
- 修改
- 删除
jQuery自定义右键菜单的更多相关文章
- jquery 自定义右键菜单
如果要自定义右键菜单,那么就需要禁止原本的右键菜单,代码如下 document.oncontextmenu = new Function("return false;");//禁止 ...
- js进阶 12-18 jquery如何实现自定义右键菜单(把问题分细)
js进阶 12-18 jquery如何实现自定义右键菜单(把问题分细) 一.总结 一句话总结:用鼠标右键事件contextmenu,阻止系统默认事件,让做好的右键菜单显示出来,并且显示在我们出现的位 ...
- 自定义右键菜单,禁用浏览器自带的右键菜单[右键菜单实现--Demo]
许多从事Web开发的会发现有些事,我们需要禁用浏览器本事自带的右键菜单,而实现自定义的右键菜单下面我们也来实现一个自定义的右键菜单 首先来创建JSP页面 <%@ page language=&q ...
- ASP.NET Aries 入门开发教程8:树型列表及自定义右键菜单
前言: 前面几篇重点都在讲普通列表的相关操作. 本篇主要讲树型列表的操作. 框架在设计时,已经把树型列表和普通列表全面统一了操作,用法几乎是一致的. 下面介绍一些差距化的内容: 1:树型列表绑定: v ...
- JavaScript自定义右键菜单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- JS简单实现自定义右键菜单
RT,一个简单的例子,仅仅讲述原理 <div id="menu" style="width: 0;height: 0;background: cadetblue;p ...
- antd Tree组件中,自定义右键菜单
最近项目中,有一个需求是自定义antd的Tree组件的右键菜单功能. 直接上代码 class Demo extends Component { state = { rightClickNodeTree ...
- AS3.0 自定义右键菜单类
AS3.0 自定义右键菜单类: /** * 自定义右键菜单类 * 自定义菜单项不得超过15个,每个标题必须至少包含一个可见字符. * 标题字符不能超过100个,并且开头的空白字符会被忽略. * 与任何 ...
- js之自定义右键菜单
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
随机推荐
- poj Firing(最大重量封闭图)
Firing 题目: 要解雇一些人,而解雇的这些人假设人跟他有上下级的关系,则跟他有关系的人也要一起解雇.每一个人都会创造一定的价值,要求你求出在最大的获利下.解雇的人最小. 算法分析: 在这之前要知 ...
- Linux X86在下面TLB机制
TLB - translation lookaside buffer 快表.直译为翻译后备缓冲器,也能够理解为页表缓冲.地址变换快速缓存. 因为页表存放在主存中,因此程序每次訪存至少须要两次:一次訪存 ...
- FastDFS设备、构造、配置()一-安装和部署
FastDFS是一个开源的.高性能的的分布式文件系统,他基本的功能包含:文件存储.同步和訪问,设计基于高可用和负载均衡,FastDFS很适用于基于文件服务的站点.比如图片分享和视频分享站点 FastD ...
- 【Android进阶】ZXing android 错误(Could not find class 'com.google.zxing.ResultPoint)
解决方法: 1.右键工程Build path, java build path,选择libraries 在右边的按钮中点击"Add Library" 选择"User li ...
- IDF - CTF - 牛刀小试
找学校CTF好地方,IDF实验室CTF训练营(http://ctf.idf.cn/). . 刚接触CTF.来玩下牛刀小试.AK了. . 好爽好爽.. 1.摩斯password 嘀嗒嘀嗒嘀嗒嘀嗒 时针它 ...
- HDU 4946 Area of Mushroom 凸包
链接:pid=4946">http://acm.hdu.edu.cn/showproblem.php?pid=4946 题意:有n个人.在位置(xi,yi),速度是vi,假设对于某个点 ...
- Docker创建MySQL集装箱
原文链接:Docker创建MySQL集装箱 这样做的目的是创建一个MySQL的image,出来的容器里自己主动启动MySQL服务接受外部连接 步骤: 1. 首先创建一个文件夹并在文件夹下创建一个Doc ...
- 教你使用vim表白
99669999996669999996699666699666999966699666699 99699999999699999999699666699669966996699666699 9966 ...
- C++ Primer笔记4_静态成员类_IO库
1.静态成员类 static成员变量与函数 static成员变量:必须在类外初始化.(const或引用类型变量必须在构造函数初始化列表里初始化) static成员函数: 不依赖于类.相当于类里的全局函 ...
- boostrap-非常好用但是容易让人忽略的地方------row
row是非常好用但是却非常容易忽略的地方. 想实现内部元素相对父级的padding=0,则在父子中间加个row.如下图 列嵌套也是同样的道理 经验之谈:学会row的用法,在手机版布局的时候会很方便,否 ...