Skip to content

Instantly share code, notes, and snippets.

@bjconlan
bjconlan / parseUnit
Last active December 20, 2015 14:49
Basic absolute conversions in javascript. Converts a subset of 'http://www.w3.org/TR/css3-values/' in pure javascript. Returns linear measurements in pixels and angles in degrees (perhaps this should be rads...)
var ppi = 96 * window.devicePixelRatio || 1; // 96 = CSS DPI/PPI reference measurement
var absoluteMeasurements = {
px : 1,
pt : 4 / 3,
pc : 12 * (4 / 3),
in : ppi,
cm : ppi / 2.54,
mm : ppi / 25.4,
deg: 1,
grad: 400 / 360,