我可以使用vh和vw指定画布尺寸吗? [英] Can I specify canvas dimensions using vh and vw?

查看:75
本文介绍了我可以使用vh和vw指定画布尺寸吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码是:

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

,它不起作用.在JavaScript中设置画布尺寸时可以使用vw和vh吗?如果可以,怎么办?

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

推荐答案

我意识到我可以使用 document.documentElement.clientWidth document.documentElement.clientHeight 进行计算分别是vw和vh.

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

这篇关于我可以使用vh和vw指定画布尺寸吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆