取得元素的左和上偏移量的方法
functiongetElementLeft(element)
{
varactualLeft=element.offsetLeft;
varcurrent=element.offsetParent;
while(current!==null)
{
actualLeft+=current.offsetLeft;
current=current.offsetParent;
}
returnactualLeft;
}
取得元素的左偏移量;
functiongetElementTop(element)
{
varactualTop=element.offsetTop;
varcurrent=element.offsetParent;
while(current!==null)
{
<spanstyle="white-space:pre"></span>actualTop+=current.offsetTop;
current=current.offsetParent;
}
returnactualTop;
}
取得元素的上偏移量;
利用offsetParent属性在Dom层次中逐级向上回溯,将每个层次偏移量合计。
热门推荐
10 生日贺卡祝福语英文简短
11 升班祝福语简短10字
12 幽默的新娘祝福语简短
13 婚礼红包祝福语简短霸气
14 祝福语简短的微信
15 祝福语送超市同事简短
16 男生节搞笑简短祝福语
17 六一祝贺文案祝福语简短
18 成语祝福语精选大全简短