js 自定义右键菜单
作者:
发光驴子 | 来源:发表于
2017-10-12 08:19 被阅读0次 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<style>
* {margin:0; padding:0;}
#ul1 {width:100px; background:#CCC; border:1px solid black; position:absolute; display:none;}
</style>
<script>
//右键菜单事件
document.oncontextmenu=function (ev) {
var scllTop=document.documentElement.scrollTop||document.body.scrollTop;
var scrollLeft=document.documentElement.scrollLeft||document.body.scrollLeft;
var oEvent=ev||event;
var oUl=document.getElementById("ul1");
oUl.style.listStyle="none";
oUl.style.display="block";
oUl.style.left=oEvent.clientX+scrollLeft+"px";
oUl.style.top=oEvent.clientY+scllTop+"px";
return false;//是阻止默认的右键事件,
};
document.onclick=function () {
var oUl=document.getElementById("ul1");
oUl.style.display="none";
}
</script>
<body style="height: 2000px">
<ul id="ul1">
<li>登录</li>
<li>ss</li>
<li>kk</li>
<li>加入</li>
</ul>
</body>
</html>
本文标题:js 自定义右键菜单
本文链接:https://www.haomeiwen.com/subject/ricnyxtx.html
网友评论