Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I specify canvas dimensions using vh and vw?

My code is:

var canvas = document.getElementById("canvas");
ctx = canvas.getContext("2d");
ctx.canvas.width = 40vw;
ctx.canvas.height = 40vh;

and it doesn't work. Is it possible to use vw and vh when setting canvas dimensions in JavaScript? If so, how?

like image 514
Jonah Avatar asked Oct 20 '22 00:10

Jonah


1 Answers

I realised I could use document.documentElement.clientWidth and document.documentElement.clientHeight to work out the vw and vh respectively.

like image 58
Jonah Avatar answered Oct 21 '22 22:10

Jonah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!