Javascript: IE8 event coordinates

无人久伴 提交于 2019-12-12 11:15:36

问题


I can't seem to find a way to get coordinates of event in IE8, it just triggers errors like... pageX undefined, clientX undefined etc. While it works find in other browsers.

This is what I was trying to do:

document.onmousemove=setcoord;

function setcoord(e){
    var xxcoord = e.pageX||(e.clientX+document.body.scrollLeft);
    var yycoord = e.pageY||(e.clientY+document.body.scrollTop);
}

Is there any workaround to get that mouse position ?..


回答1:


The following seems to work. I'm not sure its is the proper way to do this:

var x=event.clientX;
var y=event.clientY;


来源:https://stackoverflow.com/questions/11042275/javascript-ie8-event-coordinates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!