HTML5 Canvas as CSS background-image?

后端 未结 3 1131
闹比i
闹比i 2021-01-05 00:23

Is it possible to make the background image of a DIV a canvas that can be modified with getContext(\"2d\")?

3条回答
  •  Happy的楠姐
    2021-01-05 00:37

    Set the background-image of the div to this:

    "url('" + canvas.toDataURL() + "')";
    

    Edit: At that point, note that you are also free to do what you wish with the canvas, as the background-image will continue to contain only the image data that was in the canvas at the moment that you called canvas.toDataURL(). Feel free to discard or draw onto the canvas, as it will not affect your div's background at that point.

提交回复
热议问题