<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.shi{
200px;
height:200px;
background:yellow;
box-shadow: #ccc 0px 0px 10px;
position:absolute;
display: none;
}
</style>
</head>
<body>
<div class="shi">
<p>若不是你突然闯进 我生活</p>
<p>我怎会把死守的寂寞 放任了</p>
</div>
<script>
window.oncontextmenu = function ()
{
return false;
}
document.onmousedown = function(e){
let mouse = document.querySelector('.shi');
let winHeight = document.documentElement.clientHeight; //////窗口高度
let winWidth = document.documentElement.clientWidth; //////窗口宽度
let mouseHeight = e.clientY; ////鼠标距离浏览器高度
let mouseLeft = e.clientX; /////鼠标距离浏览器左侧宽度
if(e.button == '2'){
mouse.style.display = 'block';
if(winHeight - mouseHeight < 200){
mouse.style.left = mouseLeft - 200 + 'px';
mouse.style.top = mouseHeight-200 + 'px';
}else if(winWidth - mouseLeft < 200){
mouse.style.top = mouseHeight + 'px';
mouse.style.left = mouseLeft - 200 + 'px'
}else if(winWidth - mouseLeft > 200){
mouse.style.left = mouseLeft+'px';
mouse.style.top = mouseHeight+'px';
}else if(mouseHeight > 0 && mouseHeight < 200){
mouse.style.left = mouseLeft - 200 + 'px';
mouse.style.top = mouseHeight - 200 + 'px';
}
}else{
console.log(winHeight,mouseHeight);
}
}
</script>
</body>
</html>
上下左右都不会有bug的点击弹窗