Last active
October 12, 2015 11:17
-
-
Save phaistonian/a421b1bb7992ab2200ee to your computer and use it in GitHub Desktop.
Deal with sub-pixels the JS way
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 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