IE6 is getting to be pain but it still makes up (apparently) a good chunk of the browser market share, so I need to make this work.
function getPosition(e)
{
e = e || window.event;
var cursor = {x:0, y:0};
if (e.pageX || e.pageY)
{
cursor.x = e.pageX;
cursor.y = e.pageY;
}
else
{
var dex = document.documentElement;
var b = document.body;
cursor.x = e.clientX + (dex.scrollLeft || b.scrollLeft) - (dex.clientLeft || 0);
cursor.y = e.clientY + (dex.scrollTop || b.scrollTop) - (dex.clientTop || 0);
}
return cursor;
}
function outCursor(e){
var curPos = getPosition(e);
alert(curPos);
}
window.captureEvents(Event.MOUSEMOVE);
window.onmousemove = outCursor;
IE is compla开发者_StackOverflow中文版ining about the Event in window.captureEvents(Event.MOUSEMOVE);
'Event' is undefined.
I think ie6 doesn't supports captureEvents. So try
if (window.captureEvents) {
window.captureEvents(Event.MOUSEMOVE);
}
Try running the script without window.captureEvents(Event.MOUSEMOVE);
. I don't think it is necessary. Also, like someone mentioned change the window.onmousemove
to document.onmousemove
Also here is a good resource on writing this kind of script http://www.quirksmode.org/js/events_properties.html#position
精彩评论