Created
June 20, 2016 14:37
-
-
Save soluml/b386629e9dfef11af60a142f203477f3 to your computer and use it in GitHub Desktop.
Resize on event
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
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