Skip to content

Instantly share code, notes, and snippets.

@phaistonian
Last active October 12, 2015 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phaistonian/a421b1bb7992ab2200ee to your computer and use it in GitHub Desktop.
Save phaistonian/a421b1bb7992ab2200ee to your computer and use it in GitHub Desktop.
Deal with sub-pixels the JS way
function attachRounder (element) {
window.addEventListener('resize', () => makeRound(element));
makeRound(element);
}
function makeRound (element) {
let transform = window.getComputedStyle(element, null).getPropertyValue('transform');
if (transform.indexOf('matrix') !== -1) {
element.style.transform = transform.replace(/[\d\.]+/gi, function (match) { return Math.round(match);});
}
}
export default attachRounder;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment