I'm writing some javascript code that heavily manages the DOM and I'd like to be confident that my code is efficient.
I'm wondering whether there is a native, browser-provided API allowing javascript to manage complex css attributes? I am interested in performance so I would like to use tools that are as native as possible.
If I open the console on any webpage I can type and witness the following:
>>> window.document.body.style.transform = 'translate(0, 0)';
"translate(0, 0)"
>>> window.document.body.style.transform
"translate(0px, 0px)"
Obviously the style.transform property is not a simple property for it is reformatting 0 as 0px. But the value of the style.transform property is a simple string!
Is there any API for managing complex css attributes such as transform?
Something like the following?
>>> var elem = document.getElementById('some-id');
>>> elem.style.niceTransform.translate
null
>>> elem.style.niceTransform.rotate
null
>>> elem.style.niceTransform.scale
null
>>> elem.style.niceTransform.translate = 'transform(10, 20, 30)';
>>> elem.style.niceTransform.translate
CSSTransformTranslate { x: 10, y: 20, z: 30 }
>>> elem.style.niceTransform.translate.y += 20;
>>> elem.style.niceTransform.translate
CSSTransformTranslate { x: 10, y: 40, z: 30 }
Obviously I have invented the niceTransform property and CSSTransformTranslate class. Do browsers provide javascript with an api for managing complex css properties? If so, could I get a link to such documentation?
Thanks!
complex css properties? According to the spec "The format of a length value (denoted by <length> in this specification) is a <number> (with or without a decimal point) immediately followed by a unit identifier (e.g., px, em, etc.). After a zero length, the unit identifier is optional."font-styleis not a complex property. Thefont-styleproperty has no sub-properties; it is simply an inline string such as"serif"or "sans-serif". But thetransformproperty is complex - it hasscale,translate, androtateproperties, and each of those components has further sub-properties. (e.g.transformhasx,y, andzproperties).