function getElementLeft(element) { var actualLeft = element.offsetLeft; var current = element.offsetParent; while (current!==null) { actualLeft += current.offsetLeft; current = current.offsetParent; } return actualLeft; }
Ermitteln Sie den linken Offset des Elements
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; }
Verwenden Sie das offsetParent-Attribut, um Ebene für Ebene in der Dom-Hierarchie zurückzugehen und die Offsets jeder Ebene zu addieren.