質問

I want to get the total offSetTop and the total offSetLeft of a child element which have many level of parent element and may be adding up.

Is that any shorthand way, besides of adding one by one in manual ways?

役に立ちましたか?

解決

using jQuery: $( node ).offset() then .top and .left

他のヒント

To provide an answer without jQuery:

var a = Element, b = 0, c = 0;
while (a) {
    b += a.offsetLeft;
    c += a.offsetTop;
    a = a.offsetParent;
}

Where Element is your Element node for which you need an offsetLeft and offsetTop.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top