jQuery怎么判断鼠标位置是不是在浏览器窗口右下角?
1个回答
展开全部
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<p></p>
<p></p>
<p></p>
<script>
let p = document.getElementsByTagName('p'),
windowWidth = document.documentElement.clientWidth || document.body.clientWidth,
windowHeight = document.documentElement.clientHeight || document.body.clientHeight;
function mouseMove(ev)
{
console.log(windowHeight)
console.log(windowWidth)
if(ev.pageX || ev.pageY){
x=ev.pageX
y=ev.pageY
}
else{
x=ev.clientX + document.body.scrollLeft - document.body.clientLeft,
y=ev.clientY + document.body.scrollTop - document.body.clientTop ;
};
p[0].innerHTML=x
p[1].innerHTML=y
if(x==windowWidth-1&&y==windowHeight-1)
{result = "在右下角"}
else
{result = "不在右下角"}
p[2].innerHTML=result
}
document.onmousemove = mouseMove;
</script>
</body>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<p></p>
<p></p>
<p></p>
<script>
let p = document.getElementsByTagName('p'),
windowWidth = document.documentElement.clientWidth || document.body.clientWidth,
windowHeight = document.documentElement.clientHeight || document.body.clientHeight;
function mouseMove(ev)
{
console.log(windowHeight)
console.log(windowWidth)
if(ev.pageX || ev.pageY){
x=ev.pageX
y=ev.pageY
}
else{
x=ev.clientX + document.body.scrollLeft - document.body.clientLeft,
y=ev.clientY + document.body.scrollTop - document.body.clientTop ;
};
p[0].innerHTML=x
p[1].innerHTML=y
if(x==windowWidth-1&&y==windowHeight-1)
{result = "在右下角"}
else
{result = "不在右下角"}
p[2].innerHTML=result
}
document.onmousemove = mouseMove;
</script>
</body>
追问
老大,获取鼠标的位置之后不能复制内容了!咋搞?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询