Last active
November 5, 2018 12:11
-
-
Save laphilosophia/3d3e31bd97adbbfa62af0d5d9d8a9c30 to your computer and use it in GitHub Desktop.
on the window resizes, recalculate the canvas width as well, using a debounce to avoid calling too many times our canvas resizing
This file contains hidden or 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
const canvas = document.querySelector('canvas') | |
const debounce = (func) => { | |
let timer | |
return (event) => { | |
if (timer) { clearTimeout(timer) } | |
timer = setTimeout(func, 100, event) | |
} | |
} | |
window.addEventListener('resize', debounce(() => { | |
canvas.width = window.innerWidth | |
canvas.height = window.innerHeight | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment