您的位置:首页 > 其它

关于浏览器和屏幕的坐标大全(经典中的经典)

2013-07-26 09:45 239 查看
<body onclick="Text()">
<script type="text/javascript">
var strInfo="";
function Text(){
strInfo+=window.event.x; //设置或获取鼠标指针位置相对于父文档的 x 像素坐标
strInfo+="\n"+window.event.y;//设置或获取鼠标指针位置相对于父文档的 y 像素坐标。
strInfo+="<br>"+window.event.clientX;//设置或获取鼠标指针位置相对于窗口客户区域的 x 坐标,其中客户区域不包括窗口自身的控件和滚动条.
strInfo+="\n"+window.event.clientY;//设置或获取鼠标指针位置相对于窗口客户区域的 y坐标,其中客户区域不包括窗口自身的控件和滚动条.
strInfo+="<br>"+window.event.screenX; //screenX 设置或获取获取鼠标指针位置相对于用户屏幕的 x 坐标。
strInfo+="\n"+window.event.screenY; //screenX 设置或获取获取鼠标指针位置相对于用户屏幕的 y 坐标。
strInfo+="<br>"+window.event.offsetX;//offsetX 设置或获取鼠标指针位置相对于触发事件的对象的 x 坐标。
strInfo+="\n"+window.event.offsetY;//offsetX 设置或获取鼠标指针位置相对于触发事件的对象的 y坐标。
/*event.clientX返回事件发生时,mouse相对于客户窗口的X坐标,event.X也一样。但是如果设置事件对象的定位属性值为relative,event.clientX不变,而

event.X返回事件对象的相对于本体的坐标。*/
strInfo+="<br>"+document.body.scrollWidth;//上下滚动条高度距离屏幕左端的距离
strInfo+="\n"+document.body.scrollHeight;//屏幕内容距离窗口上端的距离
strInfo+="<br>"+document.body.scrollTop;//网页被卷去的高
strInfo+="\n"+document.body.scrollLeft;//网页被卷去的宽
strInfo+="<br>"+document.body.clientWidth;//网页可见区域的宽度(不会随着鼠标的变化而变化,不包括边框和滚动条);
strInfo+="\n"+document.body.clientHeight;//网页可见区域的高度(不会随着鼠标的变化而变化,不包括边框和滚动条);
strInfo+="<br>"+document.body.offsetWidth;//网页可见区域的高度(不会随着鼠标的变化而变化,包括边框和滚动条);
strInfo+="\n"+document.body.offsetHeight;//网页可见区域的高度(不会随着鼠标的变化而变化,包括边框和滚动条);
strInfo+="<br>"+window.screenTop;//网页正文部分上 有些浏览器要换成window.screenX
strInfo+="\n"+window.screenLeft;//网页正文部分左 有些浏览器要换成window.screenY
strInfo+="<br>"+window.screen.width;//返回屏幕分辨率的宽度
strInfo+="\n"+window.screen.height;//返回屏幕分辨率的高度
strInfo+="<br>"+window.screen.availWidth;//返回屏幕可用工作区的像素宽度(不包括工具栏)
strInfo+="\n"+window.screen.availHeight;//返回屏幕可用工作区的像素的高度(不包括工具栏)

document.write(strInfo);
}
</script>
</body>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: