意思搞的不是太明白,先发上来做为一个记录。
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 >
本文转自豪情博客园博客,原文链接:http://www.cnblogs.com/jikey/archive/2009/12/07/1618273.html,如需转载请自行联系原作者