How to configure Fabric.js?

I am very new to fabric.js. I downloaded the fabric.js file, but I do not know how to run it. For instance:

<html> <head> <script src="fabric.min.js"></script> </head> <body> <canvas id="canvas" width="800" height="450" style="border:1px solid #000000"></canvas> <script> var canvas = new fabric.Canvas('c1'); canvas.add(new fabric.Circle({ radius: 30, fill: '#f55', top: 100, left: 100 })); canvas.selectionColor = 'rgba(0,255,0,0.3)'; canvas.selectionBorderColor = 'red'; canvas.selectionLineWidth = 5; </script> </body> </html> 

In this script, I should see a circle. I followed this example: http://fabricjs.com/customization/

But why didn’t I see anything; What am I missing?

+5
source share
1 answer

The fabric.Canvas parameter must match the canvas id in html.

Change the line

 var canvas = new fabric.Canvas('c1'); 

to

 var canvas = new fabric.Canvas('canvas'); 

That should work.

+15
source

Source: https://habr.com/ru/post/974279/


All Articles