属性:

  1. width (Number): 定义画布的宽度;
  2. height (Number):定义画布的高度;
  3. 属于标签的属性,在canvas 同样成立,如: id, class…

    width,height 与 style 中的width的区别

    属性 width,height 定义的是 canvas 画布的长宽,表示绘图区域,其中左上角表示 (0, 0),y 轴朝下。如果使用的坐标点落在画布外面,则不显示;不设置时,默认值为: 300, 100.

style 中的 width, height 与canvas 绘图区域无关,它表示的是 canvas 标签元素在页面中展示的区域大小。当 style 中的 width,height 与属性的 width,height 不同时,则展示以style 为准,铺满整个元素,则canvas 绘图会变形。