高手的来解决一哈!!!!
怎样获得层width,Height ,还有层的位置坐标(X坐标,Y坐标,Z-index位置);我想在Javascript中获取
程序代码:
/**
++ update : 2007-12-13 By lmhllr
++ Name : getCurrentSrtle
++ Function : 取得对像的样式
++ Param : @object obj : 所要操作对象;
@string prop : 所要取得的样式名
++ use : getCurrentStyle ( this , 'width');
*/
function getCurrentStyle (obj, prop)
{
if (obj.currentStyle)
{
return obj.currentStyle[prop];
}else if (window.getComputedStyle)
{
prop = prop.replace (/([A-Z])/g, "-$1");
prop = prop.toLowerCase ();
return window.getComputedStyle (obj, "").getPropertyValue(prop);
}
return null;
}
程序代码:
/**
++ update : 2007-12-28
++ Author : lmhllr
++ Name : getPosition
++ Function : 获取元素相对文档的绝对位置,返回对象类型,{x:left,y:top}分别代表X轴和Y轴
++ Param : @object e : 所要操作的对象
++ use : getPosition('oDiv');
*/
function getPosition(e){
var left = 0;
var top = 0;
while (e.offsetParent){
left += e.offsetLeft;
top += e.offsetTop;
e = e.offsetParent;
}
left += e.offsetLeft;
top += e.offsetTop;
return {x:left, y:top};
}