获取控件Left绝对位置
function getAbsoluteLeft(id) {
var el = document.getElementById(id);
var left = el.offsetLeft - el.scrollLeft;
while (el.offsetParent != null) {
var parent = el.offsetParent;
left += parent.offsetLeft - parent.scrollLeft;
el = parent;
}
return left;
}
获取控件Top绝对位置
function getAbsoluteTop(id) {
var el = document.getElementById(id);
var top = el.offsetTop - el.scrollTop;
while (el.offsetParent != null) {
var parent = el.offsetParent;
top += parent.offsetTop - parent.scrollTop;
el = parent;
}
return top;
}
获取控件宽度
function getElementWidth(id) {
var x = document.getElementById(id);
return x.offsetWidth;
}