如何使用 FabricJS 设置椭圆 X 轴的倾斜角度?
在本教程中,我们将学习如何使用 FabricJS 设置椭圆 X 轴的倾斜角度。椭圆是 FabricJS 提供的各种形状之一。为了创建椭圆,我们将创建一个 fabric.Ellipse 类的实例并将其添加到画布上。我们的椭圆对象可以通过多种方式进行自定义,例如更改其尺寸、添加背景颜色或更改 X 轴的倾斜角度。我们可以使用 skewX 属性来实现这一点。
语法
new fabric.Ellipse({ skewX : Number }: Object)参数
options (可选) - 此参数是一个 Object,它为我们的椭圆提供额外的自定义选项。使用此参数,可以更改与对象相关的许多属性,例如颜色、光标、笔触宽度等等,其中 skewX 就是一个属性。
选项键
skewX - 此属性接受一个 Number,用于确定对象 X 轴的倾斜角度。
示例 1
当未应用 skewX 属性时
让我们举个例子来了解当未应用 skewX 属性时我们的椭圆对象是什么样子。在这种情况下,我们的椭圆对象将不会有任何角度的倾斜。
<!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 angle of skew on the X-axis of an Ellipse using FabricJS</h2>
<p>Notice that by default the object is not skewed. Here we have not applied the <b>skewX</b> property. However you can elect the object and stretch it horizontally or vertically by pressing the <b>shift</b> key. The object will get skewed.</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
将 skewX 作为键并为其分配自定义值。
在本例中,我们将了解如何为 skewX 属性分配数值。传递的值将确定沿 X 轴的倾斜。
<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 x-axis of Ellipse using FabricJS?</h2>
<p>Notice that the ellipse is skewed on the X-axis by 50 degrees in the clockwise direction because here we have applied the <b>skewX</b> property and given it a value of 50.</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",
skewX: 50,
});
// 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