代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<div id="aa" style="position:absolute;200px;height:200px;left:200px;top:1000px;border:1px solid #ccc" onclick=offset(this) ></div>
<div id="bb" style="position:absolute;200px;height:200px;border:1px solid red"></div>
<script>
var offset = function (o){
var d = document,m = Math.max,bl = m(d.body.clientLeft,d.documentElement.clientLeft),st,sl,
bt = m(d.body.clientTop,d.documentElement.clientTop),b,bb = document.getElementById('bb');
return function(o){
b = o.getBoundingClientRect();
document.getElementById("bb").innerHTML += "<br/>top:"+b.top+'px;left:'+b.left+"px";
st = m(d.body.scrollTop,d.documentElement.scrollTop),sl = m(d.body.scrollLeft,d.documentElement.scrollLeft);
bb.style.cssText +=";top:"+(b.top+st-bt)+'px;left:'+(b.left+sl-bl)+"px";
}
}()
</script>
</body>
</html>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<div id="aa" style="position:absolute;200px;height:200px;left:200px;top:1000px;border:1px solid #ccc" onclick=offset(this) ></div>
<div id="bb" style="position:absolute;200px;height:200px;border:1px solid red"></div>
<script>
var offset = function (o){
var d = document,m = Math.max,bl = m(d.body.clientLeft,d.documentElement.clientLeft),st,sl,
bt = m(d.body.clientTop,d.documentElement.clientTop),b,bb = document.getElementById('bb');
return function(o){
b = o.getBoundingClientRect();
document.getElementById("bb").innerHTML += "<br/>top:"+b.top+'px;left:'+b.left+"px";
st = m(d.body.scrollTop,d.documentElement.scrollTop),sl = m(d.body.scrollLeft,d.documentElement.scrollLeft);
bb.style.cssText +=";top:"+(b.top+st-bt)+'px;left:'+(b.left+sl-bl)+"px";
}
}()
</script>
</body>
</html>