Javascript集<;帆布>;窗口大小
我正在尝试将画布元素设置为当前窗口的大小 我在这里成功地使用了jquery:Javascript集<;帆布>;窗口大小,javascript,jquery,canvas,html5-canvas,breakout,Javascript,Jquery,Canvas,Html5 Canvas,Breakout,我正在尝试将画布元素设置为当前窗口的大小 我在这里成功地使用了jquery: function windowsize() { WIDTH = $("#canvas")[0].width = ($(window).width()); HEIGHT = $("#canvas")[0].height = ($(window).height()); } windowsize(); 我无法在普通javascript中完成同样的事情,我有以下几点: function windowsiz
function windowsize() {
WIDTH = $("#canvas")[0].width = ($(window).width());
HEIGHT = $("#canvas")[0].height = ($(window).height());
}
windowsize();
我无法在普通javascript中完成同样的事情,我有以下几点:
function windowsize(){
var ctx = document.getElementbyID("canvas");
ctx.canvas.width = window.innerWidth;
ctx.canvas.height = window.innerHeight;
}
windowsize();
以下是对上述内容的修改:
我还使用了以下页面作为参考:
谢谢 打字错误:
document.getElementbyID
应该是:
document.getElementById
ctx没有画布属性
更新示例: