横屏landscape canvas的比例不对
发布于 4 年前 作者 nalu 14194 次浏览 来自 问答

如果是 Bug:

* Bug 表现是什么?预期表现是什么?

同样的代码, 在竖屏上是正常的, 但是在横屏上就变成1:3的比例了. 如上图, 我画的是100x100的绿色方块, 开发者工具里面是正常的, 但是放到iPhone 6P上就变成上面那样了.

* 如何复现?

export default class Main {

  constructor() {

      this.loop();

  }

  loop() {

    ctx.fillStyle = “#f00”;

    ctx.fillRect(0, 0, canvas.width, canvas.height);

    ctx.fillStyle = “#0f0”;

    ctx.fillRect(0, 100, 100, 100);

    window.requestAnimationFrame(

      this.loop.bind(this),

      canvas

    )

  }

}

* 提供一个最简复现 Demo

如上.

回到顶部