0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

canvas要素の全消去

Posted at

canvas要素の内容を全消去したい場合、clearRectで全範囲を指定する方法をよく見かける。

JavaScript
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);

canvasのサイズを同じ値に指定し直すことでも全消去できる。

JavaScript
const canvas = document.getElementById('canvas');
canvas.width = canvas.width;

// または
// canvas.height = canvas.height;
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?