Hi Clothears,

Stylesheets are loaded asynchronously, and it's currently impossible to get any 
kind of event or to poll a property in every browser and in every circumstance 
(i.e. cross-domain stylesheet loading in Gecko browsers).  So your javascript 
will not get any notification of when CSS is applied.

I've done a bit of work in the area of CSS dependencies.  Along with some 
former colleagues, I defined a pattern which we called CSSP:
http://otaqui.com/blog/890/cssp-loading-css-with-javascript-and-getting-an-onload-callback/

We were using RequireJS, and wanted to "depend" on some CSS, so we wrote a 
RequireJS plugin:
https://github.com/bbc-frameworks/cssp

TLDR;  You need a rule in your CSS file that you can poll for.  We applied a 
z-index to a hidden element, and then used setInterval to keep checking for 
when the z-index property changed.

Best,

Pete




On 14 Jul 2011, at 11:54, Clothears wrote:

> There are some elements in one of my app's pages whose height and
> other style values I'd like to get as soon as possible, since I want
> to use the values to calculate and set heights of other elements. And
> I'd like to be able to either get the element's natural height or one
> I set using CSS.
> 
> So, I'm doing something like [1]:
> 
> h =
> document.defaultView.getComputedStyle(e,null).getPropertyValue("height");
> 
> where e is a pointer to my element.
> 
> But I find that if I do this right at the start of the onload
> function, I get back a zero value, whereas if I do it a bit later
> (e.g. after waiting for some ajax calls to complete), then I get the
> proper value.
> 
> So when are these style values set? The reason for this is to avoid
> what I do at the moment: compute the true height by hand and just have
> a JavaScript variable initialised to that value.
> 
> 
> [1] If/when I can sort this I can collect the border/margin/padding
> values too.
> 
> -- 
> To view archived discussions from the original JSMentors Mailman list: 
> http://www.mail-archive.com/[email protected]/
> 
> To search via a non-Google archive, visit here: 
> http://www.mail-archive.com/[email protected]/
> 
> To unsubscribe from this group, send email to
> [email protected]

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to