意思搞的不是太明白,先发上来做为一个记录。
window.onload = function(){
var a = document.getElementById('a');
a.onmousemove = function(e){
var pointer = getCroodsInDocument(e);
var b = document.getElementById('b');
b.innerHTML = 'x, y = (' + pointer.x + ',' + pointer.y + ')';
}
function getCroodsInDocument(e){
e = e || window.event;
var x = e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
var y = e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop));
return {
'x': x,
'y': y
};
}
}
var a = document.getElementById('a');
a.onmousemove = function(e){
var pointer = getCroodsInDocument(e);
var b = document.getElementById('b');
b.innerHTML = 'x, y = (' + pointer.x + ',' + pointer.y + ')';
}
function getCroodsInDocument(e){
e = e || window.event;
var x = e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
var y = e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop));
return {
'x': x,
'y': y
};
}
}
静态代码:
<div id="a">
<div id="c"></div>
</div>
<div id="b">x</div>
<div id="c"></div>
</div>
<div id="b">x</div>