码迷,mamicode.com
首页 > 其他好文 > 详细

右键菜单

时间:2015-03-13 10:46:41      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
body{
width: 100%;
height: 800px;
}
#wrpp{
width: 500px;
height: 500px;
background: #b5d3ff;
display: block;
}
#showbox{
width: 100px;
height:100px;
background: #faa;
display: none;
position: absolute;
}
</style>

</head>
<body>
<div id="wrpp">
<div id="showbox"></div>
</div>
<script type="text/javascript">
document.oncontextmenu=function(){
return false
}
document.getElementById("wrpp").onmousedown=function(e){
var e = e || window.event
if(e.button == "2"){
x=event.screenX;
y=event.screenY;
document.getElementById("showbox").style.top=x-100+"px";
document.getElementById("showbox").style.left=y-100+"px";
document.getElementById("showbox").style.display="block";
console.log(x+":"+y)
}
}
//阻止右键默认事件
//document.oncontextmenu=function(){return false}
//在return false之前写某个div显示在你鼠标的位置就成了
// 首先获取鼠标的位置,screenX,screenY,然后让div.left 和top变成那个位置,再显示出来
//当然div要设置position:absolute,然后div直接放在body下面 记到document.onclick 要让这个div消失
// $(this).mousedown(function(e){
// if(3== e.which){
// $("#showbox").css({
// display:"block"
// });
// }
// });

</script>
</body>
</html>

右键菜单

标签:

原文地址:http://www.cnblogs.com/wenhuan/p/4334402.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!