javascript 如何设置 Fabric.js?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10695308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 10:44:00  来源:igfitidea点击:

How to setup the Fabric.js?

javascriptfabricjs

提问by Gobi

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

我对fabric.js 很陌生。我已经下载了fabric.js,但我不知道如何启动它。例如:

<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/

在这个脚本中,我应该看到一个圆圈。我按照这个例子:http: //fabricjs.com/customization/

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

但为什么我什么也看不见;我错过了什么?

回答by santhgates

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

fabric.Canvas 的参数应该与 html 中的 canvas id 匹配。

Change the line

换线

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

to

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

This should work.

这应该有效。