Created
March 14, 2014 17:59
-
-
Save asolove/9553196 to your computer and use it in GitHub Desktop.
Fix Chrome WebFonts painting bug
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(){ | |
function brieflyAddCss(cssCode) { | |
var styleElement = document.createElement("style"); | |
styleElement.type = "text/css"; | |
if (styleElement.styleSheet) { | |
styleElement.styleSheet.cssText = cssCode; | |
} else { | |
styleElement.appendChild(document.createTextNode(cssCode)); | |
} | |
document.head.appendChild(styleElement); | |
setTimeout(function(){ | |
document.head.removeChild(styleElement); | |
}, 100); | |
} | |
function fixFonts(){ | |
try { | |
brieflyAddCss("* { color: white; }"); | |
} catch (e){ | |
} | |
} | |
if (window.addEventListener) { | |
window.addEventListener("load", fixFonts); | |
} else { | |
window.attachEvent("onload", fixFonts); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My first thought was popping up a div over the whole window. But it seems like Chrome caches the painting of the layers underneath and returns to that rather than recalculating when you hide it. By adding a new stylesheet, it seems to force everything to get repainted.