Skip to content

Instantly share code, notes, and snippets.

@huacnlee
Created August 3, 2010 01:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huacnlee/505621 to your computer and use it in GitHub Desktop.
Save huacnlee/505621 to your computer and use it in GitHub Desktop.
/**
* 取得对向的大小和坐标 兼容多种浏览器
* @param {Object} owner
*/
var getPos = function(owner){
if(owner == undefined){
return {top : 0, left:0 , width : 0, height : 0};
}
var e = owner;
var oTop = e.offsetTop;
var oLeft = e.offsetLeft;
var oWidth = e.offsetWidth;
var oHeight = e.offsetHeight;
while(e = e.offsetParent)
{
oTop += e.offsetTop;
oLeft += e.offsetLeft;
}
return {
top : oTop,
left : oLeft,
width : oWidth,
height : oHeight
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment