admin管理员组文章数量:1323544
When detecting mouse x and y coordinates, is it best to use event.clientX and event.clientY like this:
function show_coords(event){
var x=event.clientX;
var y=event.clientY;
alert("X coords: " + x + ", Y coords: " + y);
}
or use x and y, like this:
function show_coords(event){
var x=event.x;
var y=event.y;
alert("X coords: " + x + ", Y coords: " + y);
}
Is one method better/faster than the other? They seem to work identically to me.
When detecting mouse x and y coordinates, is it best to use event.clientX and event.clientY like this:
function show_coords(event){
var x=event.clientX;
var y=event.clientY;
alert("X coords: " + x + ", Y coords: " + y);
}
or use x and y, like this:
function show_coords(event){
var x=event.x;
var y=event.y;
alert("X coords: " + x + ", Y coords: " + y);
}
Is one method better/faster than the other? They seem to work identically to me.
Share Improve this question asked Feb 2, 2014 at 15:06 JamesJames 1,8874 gold badges22 silver badges28 bronze badges 2-
1
clientX
is more cross browser, but still not for all browsers (like FireFox). – putvande Commented Feb 2, 2014 at 15:10 -
event.x
is specified in the W3C working drafts, but not supported in many browsers? You'd be better off withclientX
, or really any of the others,offsetX
,pageX
etc.clientX
is the currently recmended standard. – adeneo Commented Feb 2, 2014 at 15:14
1 Answer
Reset to default 4I guess event.x/y are defined only in IEs. A quote from IE documentation:
"
event.clientX
: Retrieves the x-coordinate of the mouse cursor relative to the client area of the window, excluding window decorations or scroll bars.""
event.x
: Retrieves the x-coordinate of the mouse cursor relative to the parent element."
As putvande stated, clientX
maybe not cross-browser either. pageX/Y
might be a safer choice.
本文标签: javascripteventclientX and eventclientY vs eventx and eventyStack Overflow
版权声明:本文标题:javascript - event.clientX and event.clientY vs event.x and event.y - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742124737a2421885.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论