can the HTML5 Canvas element be created from the Canvas constructor

后端 未结 2 846
感情败类
感情败类 2021-02-03 17:32

I would like to be able to make Canvas elements from the constructor so that I could make a function like this.

function createCanvasContext(height,width)
{
   v         


        
相关标签:
2条回答
  • 2021-02-03 17:54
    var mycanvas = document.createElement("canvas");
    mycanvas.id = "mycanvas";
    document.body.appendChild(mycanvas);
    
    0 讨论(0)
  • 2021-02-03 17:57

    While you can do new Image() just fine, new Canvas() isn't a thing! Canvas Isn't even a thing, though HTMLCanvasElement is. Nonetheless you cannot use its constructor.

    document.createElement('canvas'); is what you want. You have to use that, just like with divs.

    0 讨论(0)
提交回复
热议问题