IE6正在变得痛苦,但它仍然占据(显然)浏览器市场份额的很大一部分,所以我需要做到这一点。
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正在抱怨window.captureEvents(Event.MOUSEMOVE)中的事件;
'事件'未定义。
答案 0 :(得分:1)
我认为ie6不支持captureEvents。所以试试
if (window.captureEvents) {
window.captureEvents(Event.MOUSEMOVE);
}
答案 1 :(得分:0)
尝试在没有window.captureEvents(Event.MOUSEMOVE);
的情况下运行脚本。我觉得没必要。另外,如有人提及,请将window.onmousemove
更改为document.onmousemove
此外,这是编写此类脚本http://www.quirksmode.org/js/events_properties.html#position
的良好资源