Created
July 30, 2017 17:12
-
-
Save samuelantonioli/b6ad7c8065e056f6a4ce72d3471ff3d6 to your computer and use it in GitHub Desktop.
Font Smoothing Fix
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
/** | |
* if you try to apply font smoothing | |
* using css rules you'll notice that | |
* Chrome ignores it | |
* because antialiasing under Mac OSX | |
* is deprecated (for good reasons). | |
* | |
* This workaround fixes this. | |
* You should only use this if you | |
* know what implications it has, | |
* i.e. subpixel rendering vs this. | |
* | |
* one-liner (needs minimum one existing stylesheet): | |
* document.styleSheets[0].insertRule('html {-webkit-font-smoothing: antialiased}', 0); | |
**/ | |
(function() { | |
var sheet = function() { | |
// https://davidwalsh.name/add-rules-stylesheets | |
var style = document.createElement('style'); | |
style.appendChild(document.createTextNode('')); | |
document.head.appendChild(style); | |
return style.sheet; | |
} | |
var smooth = function() { | |
var s = sheet(), | |
// css selector | |
c = '.font-smoothing', | |
r = 'text-rendering: auto; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;'; | |
if (s.insertRule) { | |
s.insertRule(c+' {'+ r +'}', 0); | |
} else if (s.addRule) { | |
s.addRule(c, r, 0); | |
} | |
} | |
smooth(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment