标签:
<!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