Skip to content

Instantly share code, notes, and snippets.

@soluml
Created June 20, 2016 14:37
Show Gist options
  • Save soluml/b386629e9dfef11af60a142f203477f3 to your computer and use it in GitHub Desktop.
Save soluml/b386629e9dfef11af60a142f203477f3 to your computer and use it in GitHub Desktop.
Resize on event
var isResizing;
function resize() {
var canvas = document.getElementById('canvas');
canvas.width = document.body.offsetWidth;
canvas.height = document.body.offsetHeight;
}
//Setup Dimensions and adjust on resize
window.addEventListener('resize', window.requestAnimationFrame ? () => {
//Supports requestAnimationFrame
if(!isResizing) {
isResizing = window.requestAnimationFrame(() => {
isResizing = 0;
resize();
});
}
} : () => {
//Does not support requestAnimationFrame
clearTimeout(isResizing);
isResizing = setTimeout(resize, 66);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment