Skip to content

Instantly share code, notes, and snippets.

@qmmr
Last active December 13, 2015 18:59
Show Gist options
  • Save qmmr/4959848 to your computer and use it in GitHub Desktop.
Save qmmr/4959848 to your computer and use it in GitHub Desktop.
Force repaint after resizing window
(function(window) {
var resizeTimeoutId;
// instead replacing event attach
// if you want to consider other browsers use if (window.addEventListener)
// window.onresize = window_resize;
if (window.attachEvent) {
window.attachEvent('onresize', function() {
window_resize(e);
});
}
function repaint () {
// console.log('resizeTimeoutId',resizeTimeoutId);
// force repaint i.e. IE7 bug
document.body.className = document.body.className;
}
function window_resize(e) {
// console.log('window_resize');
window.clearTimeout(resizeTimeoutId);
resizeTimeoutId = window.setTimeout(repaint, 100);
}
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment