+ 6
Responsive Canvas
How can I make canvas responsive?
8 ответов
+ 3
Thank you everyone 🤩
+ 2
that's quite tricky ;P
you must resize the canvas dimensions as soon as viewport get resized and redraw its content accordingly ^^
+ 2
Window.innerWidth
+ 2
yes, and you should define how the redrawn is handled: roughly responsive or not... but canvas size must have dimensions (in pixel) very differents... that's why usually canvas is used with fixed dimensions ;)
+ 2
Canvas.width = window.innerWidth
Canvas.height = window.innerHeight
+ 2
Sofi (DM❌) only if you define canvas css dimensions to fit viewport ^^
anyway, with big sized viewports, high sized canvas would be less efficient: it could be smart to have canvas size reduced related to viewport size ;P
+ 2
window. onresize=function(){
canvas.height=window. inneHeight
canvas.width=window.innerWidth
}
+ 1
visph Ohhh, that is a bit difficult 🙁