如何使用 FabricJS 设置椭圆控制角的大小?
在本教程中,我们将学习如何使用 FabricJS 设置椭圆控制角的大小。对象的控制角允许我们缩放、拉伸或更改其位置。我们可以通过多种方式自定义我们的控制角,例如为其添加特定颜色、更改其大小等。我们可以使用cornerSize属性更改大小。
语法
new fabric.Ellipse({ cornerSize: Number }: Object)参数
options (可选) - 此参数是一个对象,它为我们的椭圆提供额外的自定义。使用此参数,可以更改与cornerSize属性相关的对象的颜色、光标、笔划宽度以及许多其他属性。
选项键
cornerSize - 此属性接受一个数字,允许我们操作所选对象控制角的大小。其默认值为 13。
示例 1
控制角的默认大小
以下示例描述了椭圆对象在被主动选中时控制角的默认大小。
<!DOCTYPE html>
<html>
<head>
<!-- Adding the Fabric JS Library-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script>
</head>
<body>
<h2>Setting the size of the controlling corners of an Ellipse using FabricJS</h2>
<p>Select the ellipse and notice its controlling corners. This is the default size of the controlling corners. Here we have not used the <b>cornerSize</b> property. </p>
<canvas id="canvas"></canvas>
<script>
// Initiate a canvas instance
var canvas = new fabric.Canvas("canvas");
// Initiate an ellipse instance
var ellipse = new fabric.Ellipse({
left: 215,
top: 100,
fill: "white",
rx: 90,
ry: 50,
stroke: "#c154c1",
strokeWidth: 5,
borderColor: "#daa520",
cornerColor: "rgb(255,20,147)",
});
// Adding it to the canvas
canvas.add(ellipse);
canvas.setWidth(document.body.scrollWidth);
canvas.setHeight(250);
</script>
</body>
</html>示例 2
将cornerSize作为键传递自定义值
在此示例中,我们将cornerSize属性作为键传递,其值为 7。我们可以看到当椭圆对象被选中时,这如何改变了控制角的大小。
<!DOCTYPE html>
<html>
<head>
<!-- Adding the Fabric JS Library-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script>
</head>
<body>
<h2>How to set the size of the controlling corners of Ellipse using FabricJS</h2>
<p>Select the ellipse and notice the size of its controlling corners. We have set <b>cornerSize</b> at 7. </p>
<canvas id="canvas"></canvas>
<script>
// Initiate a canvas instance
var canvas = new fabric.Canvas("canvas");
// Initiate an ellipse instance
var ellipse = new fabric.Ellipse({
left: 215,
top: 100,
fill: "white",
rx: 90,
ry: 50,
stroke: "#c154c1",
strokeWidth: 5,
borderColor: "#daa520",
cornerColor: "rgb(255,20,147)",
cornerSize: 7,
});
// Adding it to the canvas
canvas.add(ellipse);
canvas.setWidth(document.body.scrollWidth);
canvas.setHeight(250);
</script>
</body>
</html>
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP