高手的来解决一哈!!!!
怎样获得层width,Height ,还有层的位置坐标(X坐标,Y坐标,Z-index位置);我想在Javascript中获取
用这个函数吧!
[code]/**
++ 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;
}
[/code]
[[it] 本帖最后由 lmhllr 于 2008-4-4 15:10 编辑 [/it]] 另外,如果对象没有设置位置和坐标,又想取得它的绝对位置,用下面函数
[code]
/**
++ 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};
}
[/code]
谢谢了
我回去试试 不行的话就找你 不过高手回答的应该是对的! lmllr你是直接把Prototype的代码搬过来给他哇~~~~~回复 5# 的帖子
哦..是prototype上的啊,不知道,前段时间做拖曳在代码库里搜到改的....页:
[1]
