LoginSignup
0
1

More than 1 year has passed since last update.

canvasが表示されない時にチェックすること

Posted at

数年ぶりにフロントを触って色々ど忘れしてます…
初歩的なところでつまづいてしまったので、忘れないようにメモします

canvasが表示されない時にチェックすること

const stage = document.querySelector("canvas");
const ctx = stage.getContext("2d");

this.stage.style.width = width + "px";
this.stage.style.height = height + "px";
this.stage.width = width;
this.stage.height = height;
  • canvas要素にwidth,heightを指定するときはpxをつける。
  • contextにwidth,heightを指定するときはpxをつけない。

自分の場合は↓のようにまとめてpxをつけてしまっていたのでcanvasが表示されなくなっていました。
this.stage.style.width = this.stage.width = height + "px";

おふ…

0
1
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
1