Geeks With Blogs


What I do:

Identity Mine

MVVM Light


What I am:

Microsoft Most Valuable Professional, Client Application Development

Microsoft Certified Technology Specialist, Windows Presentation Foundation

WPF disciples


View my profile on LinkedIn

Creative Commons License
Diary of a Code Trotter by Laurent Bugnion is licensed under a Creative Commons Attribution 3.0 Unported License

All source code on this blog is licensed under the MIT license.

Copyright (c) 2006 - 2011 GalaSoft Laurent Bugnion

Laurent Bugnion (GalaSoft) Diary of a Code Trotter
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.
Posted on Saturday, January 27, 2007 10:49 PM Technical stuff , JavaScript , Website | Back to top

Comments on this post: JavaScript: CSS length manipulation and conversion

Comments are closed.
Comments have been closed on this topic.
Copyright © Laurent Bugnion | Powered by: