Js的总结
1、 一个div要呈现在另外一个div前面的话,用绝对路径,找一个相对路径的参考父控件就能很好的控制div呈现了。下面是怎么取父控件的长宽高等。
//获取控件左绝对位置
function getAbsoluteLeft(objectId) {
o= document.getElementById(objectId)
oLeft= o.offsetLeft
while (o.offsetParent !=null) {
oParent= o.offsetParent
oLeft+= oParent.offsetLeft
o= oParent
}
return oLeft
}
//获取控件上绝对位置
function getAbsoluteTop(objectId) {
o= document.getElementById(objectId);
oTop= o.offsetTop;
while (o.offsetParent !=null) {
oParent= o.offsetParent
oTop+= oParent.offsetTop// Add parent topposition
o= oParent
}
return oTop
}
//获取控件宽度
function getElementWidth(objectId) {
x= document.getElementById(objectId);
return x.offsetWidth;
}
//获取控件高度
function getElementHeight(objectId) {
x= document.getElementById(objectId);
return x.offsetHeight;
}