Posted in Javascript onSeptember 17, 2014
function getElementLeft(element) { var actualLeft = element.offsetLeft; var current = element.offsetParent; while (current!==null) { actualLeft += current.offsetLeft; current = current.offsetParent; } return actualLeft; }
取得元素的左偏移量;
function getElementTop(element) { var actualTop = element.offsetTop; var current = element.offsetParent; while (current!==null) { <span style="white-space:pre"> </span>actualTop += current.offsetTop; current = current.offsetParent; } return actualTop; }
取得元素的上偏移量;
利用offsetParent属性在Dom层次中逐级向上回溯,将每个层次偏移量合计。
取得元素的左和上偏移量的方法
- Author -
whsnow声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@