function getPosition(element) {
if(element.parentNode === null) {
return false;
}
var parent = null;
var pos = [];
var box;
if(element.getBoundingClientRect){
box = element.getBoundingClientRect();
return {left:box.left , top:box.top};
}else{
pos = [element.offsetLeft, element.offsetTop];
parent = element.offsetParent;
if (parent != element) {
while (parent) {
pos[0] += parent.offsetLeft;
pos[1] += parent.offsetTop;
parent = parent.offsetParent;
}
}
}
return {left:pos[0], top:pos[1]};
}
注意:本文归作者所有,未经作者允许,不得转载