如何用js新建一个canvas?

2024-12-28 14:22:46
推荐回答(2个)
回答1:

用js新建canvas的方法如下:
var canvas = document.createElement('canvas');
canvas.id = "CursorLayer";
canvas.width = 1224;
canvas.height = 768;
canvas.style.zIndex = 8;
canvas.style.position = "absolute";
canvas.style.border = "1px solid";
document.body.appendChild(canvas);
注意:此处一定要追加到body里面。

回答2:








var canvasList = document.getElementById('lineArea');
var canvas = document.createElement('canvas');
canvasList.appendChild(canvas);
canvas.width = 1000; //☜
canvas.height = 500;
canvas.style.backgroundColor = '#FF0000';


相关问答