W3C home > Mailing lists > Public > www-style@w3.org > April 2008

Re: [cssom-view] Why is body's offsetParent null ?

From: Daniel Glazman <daniel.glazman@disruptive-innovations.com>
Date: Wed, 23 Apr 2008 11:10:34 +0200
Message-ID: <480EFD0A.5090209@disruptive-innovations.com>
To: "www-style@w3.org" <www-style@w3.org>

Anne van Kesteren wrote:

> Actually, you would probably always use getBoundingClientRect() as 
> that's far more consistent and reliable than any of the offset* 
> attributes. They are mainly defined because lots of legacy scripts use 
> them currently to calculate the position of an element using while loops 
> (which the specification handles fine).

So the behavioural difference between body and other elements is
introduced because of MSIE but the Web is full of the following
script:

var t = 0;
var p = myElement;
while (p) {
   t += p.offsetTop;
   p =  p.offsetParent;
}
// use t

Because of the change you introduce saying document.body.offsetTop
is now always zero, such scripts will give an erroneous result for
non-IE browsers. Right ?

</Daniel>
Received on Wednesday, 23 April 2008 09:11:10 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:55:05 GMT