Skip to content

0C How to set the size of the Canvas

Luis Murillo Baltodano edited this page Jul 29, 2020 · 1 revision

The size function

preset(({size}) => {
    size()
})

If you don't pass arguments to the function, the canvas's size will attach the window.innerWidth and window.innerHeight values to the canvas width and height respectively

Set a fixed size

size({
    width: 400,
    height: 300
})

Set a dynamic size

size({
    width: () => element.clientWidth,
    height: () => element.clientHeight
})

If your element changes its width the window resize event it will change the size of the canvas as well

Clone this wiki locally