获取offsetTop和offsetLeft值的js代码(兼容)
发布时间:2016-12-30 来源:查字典编辑
摘要:复制代码代码如下:functionoffsetTop(elements){vartop=elements.offsetTop;varpare...
复制代码 代码如下:
function offsetTop( elements ){
var top = elements.offsetTop;
var parent = elements.offsetParent;
while( parent != null ){
top += parent.offsetTop;
parent = parent.offsetParent;
};
return top;
};
function offsetLeft( elements ){
var left = elements.offsetLeft;
var parent = elements.offsetParent;
while( parent != null ){
left += parent.offsetLeft;
parent = parent.offsetParent;
};
return parent;
};