获取鼠标坐标 clientX clientY 事件属性
2011-07-12 09:18
393 查看
定义和用法
clientX 事件属性返回当事件被触发时鼠标指针向对于浏览器页面(或客户区)的水平坐标。客户区指的是当前窗口。语法
event.clientX
提示和注释
注释:2 级 DOM 没有提供把窗口坐标转换为文档坐标的标准方法。在 IE 以外的浏览器,使用 window.pageXOffset 和 window.pageYOffset 即可。
实例
下面的例子可显示出事件发生时鼠标指针的坐标:<html> <head> <script type="text/javascript"> function show_coords(event) { x=[code]event.clientX
y=
event.clientY
alert("X coords: " + x + ", Y coords: " + y)
}
</script>
</head>
<body onmousedown="show_coords(event)">
<p>Click in the document. An alert box will alert
the x and y coordinates of the mouse pointer.</p>
</body>
</html>[/code]
TIY
clientX显示鼠标指针的坐标。
ClientY 事件属性
返回 Event 对象参考手册
定义和用法
clientY 事件属性返回当事件被触发时鼠标指针向对于浏览器页面(客户区)的垂直坐标。客户区指的是当前窗口。
语法
event.clientY
提示和注释
注释:注意,该坐标不考虑文档的滚动。如果事件发生在窗口的顶部,无论文档滚了多远,clientY 的值都是 0。但是,2 级 DOM 没有提供把窗口坐标转换为文档坐标的标准方法。在 IE 以外的浏览器,使用 window.pageXOffset 和 window.pageYOffset 即可。
实例
下面的例子可显示出事件发生时鼠标指针的坐标:<html> <head> <script type="text/javascript"> function show_coords(event) { x=[code]event.clientX
y=
event.clientY
alert("X coords: " + x + ", Y coords: " + y)
}
</script>
</head>
<body onmousedown="show_coords(event)">
<p>Click in the document. An alert box will alert
the x and y coordinates of the mouse pointer.</p>
</body>
</html>[/code]
TIY
clientY显示鼠标指针的坐标
相关文章推荐
- Python2.7: 使用Pyhook模块监听鼠标键盘事件-获取坐标
- js鼠标事件中的clientX/clientY,screenX/screenY,pageX/pageY,offsetX/offsetY,layerX/layerY,x/y
- JavaScript鼠标事件对象的坐标属性整理
- 鼠标事件的screenY,pageY,clientY,layerY,offsetY属性详解
- js向body创建对象、对象属性、对象事件,js获取元素坐标、元素边框大小、真实大小
- Javascript事件与鼠标坐标的属性
- JavaScript-4.6鼠标事件监听,获取鼠标坐标window.event---ShinePans
- js 获取坐标 通过JS得到当前焦点(鼠标)的坐标属性
- js-事件1_获取鼠标坐标clientX+scrollLeft及兼容性写法_跟随鼠标移动的divs
- 获取事件目标对象的位置坐标或者鼠标位置坐标(兼容IE和火狐)
- e.pageX;event.clientX,event.clientY,scrollLeft,clientLeft获取鼠标位置
- screen,client,page三种确定鼠标坐标的区别和原生JS事件写法,区别于Jquery的$.on(x,y);和$.click()
- Flex中通过获取鼠标所在的X、Y坐标进行事件分配
- (javascript) 获取鼠标事件发生坐标的问题
- 鼠标事件获取鼠标坐标
- 发现:Click事件也能获取鼠标单击的坐标
- js 获取坐标 通过JS得到当前焦点(鼠标)的坐标属性
- 获取事件目标对象的位置坐标或者鼠标位置坐标(兼容IE和火狐)
- 发现:Click事件也能获取鼠标单击的坐标
- JavaScript-4.6鼠标事件监听,获取鼠标坐标window.event---ShinePans