HTML:
  <div class="canvas-wrapper">     <canvas id="myCanvas"></canvas>   </div> CSS
.canvas-wrapper {     width: 900px;     min-height: 600px;  }   #myCanvas{      border:1px solid red;      position: absolute;      top:22px;      left:0px;      height: 100%;      width: 99%;  } JS
var myCanvas = new fabric.Canvas('myCanvas'); My canvas get resized to 300x150 after it's been initialized, why?
To do it, simply set the width and height properties of the Canvas object, and then redraw the canvas contents: Canvas . width = 600 ; Canvas . height = 500 ; drawScreen ();
You can get the width and height of a canvas element simply by accessing those properties of the element. For example: var canvas = document. getElementById('mycanvas'); var width = canvas.
in the latest version, you will have to do something like:
var canvas = new fabric.Canvas('myCanvas'); canvas.setHeight(500); canvas.setWidth(800); .... Your code ....
canvas.renderAll(); Works fine for me..
For dynamically changing size, this works too
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With