Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@asolove
Created March 14, 2014 17:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asolove/9553196 to your computer and use it in GitHub Desktop.
Save asolove/9553196 to your computer and use it in GitHub Desktop.
Fix Chrome WebFonts painting bug
(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);
}
})();
@asolove
Copy link
Author

asolove commented Mar 14, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment