Last active
December 19, 2015 08:38
-
-
Save oslego/5926655 to your computer and use it in GitHub Desktop.
Convert a CSS Shape polygon path from pixels to ems
This file contains 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 convertPixelPathToEm(path){ | |
return path.trim().split(/,\s?/).map(function(pair){ | |
return pair.trim().split(/\s+/).map(function(value){ | |
value = parseInt(value, 10); | |
value = (value === 0) ? 0 : (value / 16).toFixed(2) | |
return value + 'em' | |
}).join(' ') | |
}).join(', ') | |
} | |
var pxString = '99px 0px, 39px 71px, 60px 112px, 43px 154px, 117px 179px, 481px 0px, 99px 0px' | |
var emString = convertPixelPathToEm(pxString) | |
console.log(emString) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment