Skip to content

Instantly share code, notes, and snippets.

@laphilosophia
Last active November 5, 2018 12:11
Show Gist options
  • Save laphilosophia/3d3e31bd97adbbfa62af0d5d9d8a9c30 to your computer and use it in GitHub Desktop.
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
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