How to setup the Fabric.js?

帅比萌擦擦* 提交于 2019-12-06 03:35:53

问题


I am very new to fabric.js. I have downloaded the fabric.js, but I don't know how to start it. For example:

<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 supposed to see a circle. I followed this example: http://fabricjs.com/customization/

But why I couldn't see anything; what I am missing?


回答1:


The parameter of fabric.Canvas should match the canvas id in html.

Change the line

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

to

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

This should work.



来源:https://stackoverflow.com/questions/10695308/how-to-setup-the-fabric-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!