如何使用 FabricJS 在缩放圆形时锁定翻转?
在本教程中,我们将学习如何使用 FabricJS 在缩放圆形时锁定翻转。就像我们可以在画布上指定圆形对象的
语法
new fabric.Circle({ lockScalingFlip : Boolean }: Object)参数
options (可选) − 此参数是一个 对象,它为我们的圆形提供了额外的自定义。使用此参数,可以更改与
选项键
lockScalingFlip − 此属性接受一个 布尔值。如果我们将其赋值为“true”,则在缩放期间将不允许对象翻转。
示例 1
画布中圆形对象的默认行为
让我们看一个例子来了解当不使用 lockScalingFlip 属性时圆形对象的默认行为。
<!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 lock the flipping during scaling of circle using FabricJS</h2>
<p>Select the circle and try to scale it up or down. You will notice that the circle flips while scaling. This is the default behavior. Here we haven't used the <b>lockScalingFlip</b> property but by default it is set to False.</p>
<canvas id="canvas"></canvas>
<script>
// Initiate a canvas instance
var canvas = new fabric.Canvas("canvas");
var circle = new fabric.Circle({
left: 115,
top: 50,
fill: "white",
radius: 50,
stroke: "black",
strokeWidth: 5,
});
// Adding it to the canvas
canvas.add(circle);
canvas.setWidth(document.body.scrollWidth);
canvas.setHeight(250);
</script>
</body>
</html>示例 2
将 lockScalingFlip 作为键传递,值为“true”
在此示例中,我们将看到如何通过使用 lockScalingFlip 属性来停止圆形对象在缩放时翻转的能力。
<!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 lock the flipping during scaling of circle using FabricJS</h2>
<p>Select the object and try to scale it up or down. Observe that the circle will no longer flip during scaling, as we have set <b>lockScalingFlip</b> to True. </p>
<canvas id="canvas"></canvas>
<script>
// Initiate a canvas instance
var canvas = new fabric.Canvas("canvas");
var circle = new fabric.Circle({
left: 115,
top: 50,
fill: "white",
radius: 50,
stroke: "black",
strokeWidth: 5,
lockScalingFlip: true
});
// Adding it to the canvas
canvas.add(circle);
canvas.setWidth(document.body.scrollWidth);
canvas.setHeight(250);
</script>
</body>
</html>
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP