Last active
December 16, 2015 22:20
-
-
Save kflorence/5506380 to your computer and use it in GitHub Desktop.
Convert from em to px and vice versa.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function unit( scope ) { | |
return parseInt( window.getComputedStyle( scope || document.body ).fontSize, 10 ); | |
} | |
function pxToEm( px, scope ) { | |
return ( parseInt( px, 10 ) / unit( scope ) ).toFixed( 8 ) + 'em'; | |
} | |
function emToPx( em, scope ) { | |
return Math.round( parseFloat( em ) * unit( scope ) ) + 'px'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment