如何使用 FabricJS 设置椭圆在 Y 轴上的倾斜角度?
在本教程中,我们将学习如何使用 FabricJS 设置椭圆在 Y 轴上的倾斜角度。椭圆是 FabricJS 提供的各种形状之一。为了创建椭圆,我们将必须创建一个 fabric.Ellipse 类的实例并将其添加到画布上。我们的椭圆对象可以通过多种方式进行自定义,例如更改其尺寸、添加背景颜色或更改 Y 轴上的倾斜角度。我们可以使用 skewY 属性来实现这一点。
语法
new fabric.Ellipse({ skewY : Number }: Object)参数
options (可选) - 此参数是一个 对象,它为我们的椭圆提供了额外的自定义选项。使用此参数,可以更改与对象相关的许多属性,例如颜色、光标、描边宽度,其中 skewY 就是一个属性。
选项键
skewY - 此属性接受一个 数字,用于确定对象在 Y 轴上的倾斜角度。
示例 1
当未应用 skewY 属性时
让我们看一段代码来了解当未应用 skewY 属性时,我们的椭圆对象是如何显示的。在这种情况下,我们的椭圆对象将没有倾斜。
<!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 angle of skew on Y-axis of Ellipse using FabricJS?</h2>
<p>Notice there is no angle of skew here as we have not applied the <b>skewX</b> or <b>skewY</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: 115,
top: 50,
rx: 80,
ry: 50,
fill: "#ff1493",
});
// Adding it to the canvas
canvas.add(ellipse);
canvas.setWidth(document.body.scrollWidth);
canvas.setHeight(250);
</script>
</body>
</html>示例 2
将 skewY 作为键并为其分配自定义值。
在本例中,我们将看到如何为 skewY 属性分配数值。传递的值将决定沿 Y 轴的倾斜程度。
<!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 angle of skew on y-axis of Ellipse using FabricJS?</h2>
<p>Here the ellipse is skewed on the Y-axis by 30 degrees, as we have applied the <b>skewY</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: 115,
top: 50,
rx: 80,
ry: 50,
fill: "#ff1493",
skewY: 30,
});
// 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