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

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

From: Mike Wilson <mikewse@hotmail.com>
Date: Wed, 23 Apr 2008 12:28:30 +0200
Message-ID: <BAY116-DAV90D8A641EB1F857516DFBA4E30@phx.gbl>
To: "'Www-style'" <www-style@w3.org>
Cc: "'Daniel Glazman'" <daniel.glazman@disruptive-innovations.com>
Message-ID: <016601c8a52c$c63a9050$0a01a8c0@mikedeskxp>

> 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

When you want to find the offset all the way up to the top then
actually both IE and CSSOM gets it right. I made a comparison table
here a while ago:
http://www.nabble.com/RE%3A--cssom-view--small-update-p16061295.html

Though, the CSSOM scheme will break down if you want to know the 
offset to the body element as there is no way to get at this 
information.

In particular, as Garrett pointed out, this offset is available in all
browsers except Opera (and CSSOM) when using position:relative on the 
body element:
http://www.nabble.com/Re%3A--cssom-view--small-update-p16063070.html

> Because of the change you introduce saying document.body.offsetTop
> is now always zero

This is actually part of a long discussion Garrett/dhtmlkitchen and I 
have had with Anne about the suggested offset* algorithm.
You can find parts of it here:
http://www.nabble.com/-cssom-view--New-WD-%22CSSOM-View-Module%22-td15679118
html
http://www.nabble.com/-cssom-view--small-update-td15872317.html
http://www.nabble.com/Re%3A--cssom-view--small-update-td16589829.html

Best regards
Mike Wilson
Received on Wednesday, 23 April 2008 10:29:19 GMT

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