PHP速学视频免费教程(入门到精通)
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
在本教程中,我们将学习如何使用 FabricJS 设置 Circle 的最小允许比例。圆形是 FabricJS 提供的各种形状之一。为了创建一个圆圈,我们必须创建一个 Fabric.Circle 类的实例并将其添加到画布中。我们可以通过添加填充颜色来自定义圆形对象,消除其边框,甚至更改其尺寸。同样,我们还可以使用 minScaleLimit 属性来设置其允许的最小比例。
new fabric.Circle({ minScaleLimit : Number }: Object)
选项(可选) - 此参数是一个对象 为我们的圈子提供额外的定制。使用此参数,可以更改与 minScaleLimit 为属性的对象相关的颜色、光标、边框宽度和许多其他属性。
minScaleLimit - 此属性接受数字 strong> 作为允许我们控制圆的最小允许比例的值。
默认圆形对象的外观
让我们看一下代码,看看当不使用 minScaleLimit 属性时,圆形对象是什么样子。在这种情况下,我们将能够自由缩放对象,因为没有设置最小限制。
<!-- Adding the Fabric JS Library--> <script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script> <h2>Setting the minimum allowed scale value of circle using FabricJS</h2> <p>Select the object and scale it down by dragging one of its controlling corners. Here you can scale down the object freely since there is no minimum limit set.</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, radius: 50, fill: "#ff1493" }); // Adding it to the canvas canvas.add(circle); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); </script>
将 minScaleLimit 属性作为带有自定义值的键传递
在此示例中,我们将看到为 minScaleLimit 属性赋值如何更改画布中圆形对象的最小允许比例值。这里我们使用 0.8 作为值,这意味着我们将无法将对象缩小到半径小于 64 像素的半径,该半径是通过半径 * 限制计算的(0.8 * 80 = 64 像素)。
<!-- Adding the Fabric JS Library--> <script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script> <h2>Setting the minimum allowed scale value of circle using FabricJS</h2> <p>Select the object and try to scale it down by dragging one of its controlling corners. You cannot scale down the object freely, as we have set <b>minScaleLimit</b> at 0.8. So, the minimum scale of the circle must be at least 80% of the original radius, beyond which you cannot scale it down any further. </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, radius: 80, fill: "#ff1493", minScaleLimit: 0.8 }); // Adding it to the canvas canvas.add(circle); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); </script>
已抢7329个
抢已抢95407个
抢已抢14926个
抢已抢52642个
抢已抢195814个
抢已抢87480个
抢