/getEmPixels

Allows you to accurately obtain an element’s em value in pixels using JavaScript.

Primary LanguageJavaScript

GetEmPixels

Allows you to accurately obtain an element’s em value in pixels using JavaScript. No more blindly dividing by hard-coded values.

Demo: http://www.matanich.com/examples/get-em-pixels/

Article: http://www.matanich.com/2013/06/24/em-values-javascript/

The basics

GetEmPixels is simple to use and has only one function.

// Get the em or rem value of the documentElement
getEmPixels();

// Get the em value of the #footer element
getEmPixels(document.getElementById('footer'));

Size and delivery

Currently, getEmPixels.js compresses to around 481 bytes (~0.47 KB) after minify. To minify, you might try these online tools: [Microsoft Ajax Minifier]:(http://ajaxmin.codeplex.com/), [Uglify]:(http://marijnhaverbeke.nl/uglifyjs), [Yahoo Compressor]:(http://refresh-sf.com/yui/), or Closure Compiler.

Support

GetEmPixels supports a broad range of browsers and devices (there are currently no known unsupported browsers).