Jan 24 2007
CssLength class: In the course of improving my DHTML PositionedNode, one thing I really wanted is to be able to handle other units than just pixels. In order to do that, some conversions are needed. To make this easier, I developed a helper class named CssLength.
Converting from one unit to the other can be tricky. The conversion depends on quite a few things (mostly the way font size is set in the node’s hierarchy in the DOM), and there is not a simple arithmetic way to convert ems to pixels for example. This class provides a factor calculation allowing easy conversion, by using the browser’s own CSS engine. It also provides a few helper methods, for example to extract the unit from the CSS string, to add or substract pixels or other units from the value, etc…
var oCssLength = new gslb.CssLength( "2.2em" ); oCssLength.addPixels( 150 ); document.getElementById( "divTest" ).style.left = oCssLength.toString();
Creating and working with a CSS length instance
More information about the CssLength class.