window.getcomputedstyle()
returns cssstyledeclaration
object resolved style properties of element.
is object kept up-to-date page changes? example, guaranteed work?
var style = window.getcomputedstyle(mydiv); assert(mydiv.display == 'block'); mydiv.style.display = 'none'; assert(mydiv.style.display == 'none'); // magically updated
i've noticed objects returned calling getcomputedstyle()
not equal each other. assumed couldn't cache result of getcomputedstyle()
since it's read-only. accessing properties return latest resolved value?
var style1 = window.getcomputedstyle(mydiv); mydiv.style.display = 'none'; var style2 = window.getcomputedstyle(mydiv); assert(style1 != style2); // not same object (var = 0; < style1.length; i++) assert(style1[i] == style2[i]);
according css object model, getcomputedstyle
defined as
partial interface window { [newobject] cssstyledeclaration getcomputedstyle( element elt, optional domstring? pseudoelt ); };
effectively, each time call it, different object. that's because of [newobject]
:
if
[newobject]
extended attribute appears on regular or static operation, indicates when calling operation, reference newly created object must returned.
however, returned declaration must live:
return live css declaration block following properties:
- readonly flag: set.
- declarations: longhand properties supported css properties, in lexicographical order, value being resolved value computed obj using style rules associated doc.
- parent css rule: null.
- owner node: obj.
the spec doesn't explicitly define "live" means, guess it's reasonable enough.
Comments
Post a Comment