Home >Web Front-end >JS Tutorial >How to disable unified scaling in canvas using FabricJS?
In this article, we will learn how to disable unified scaling in canvas using FabricJS. In FabricJS, when an object is dragged from a corner, the object transforms proportionally. However, we can disable this behavior using the uniformScaling attribute.
new fabric.Canvas(element: HTMLElement|String, { uniformScaling: Boolean }: Object)
##Element - This parameter is the element itself, Can be derived using
Options (optional) - This parameter is an object that provides additional customization of our canvas. Using this parameter, you can change canvas-related properties such as color, cursor, border width, and many other properties, of which uniformScaling is a property. It accepts a Boolean value that determines whether the object should be scaled proportionally. Its default value is True.
uniformScaling is set to False , the scaling is uneven. Starting with FabricJS version 4, the property uniScaleTransform has been removed and replaced by uniformScaling.
<!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> <div style="padding: 10px; font-weight: bold; margin-left: 32px"> How to disable uniform scaling in canvas using FabricJS? </div> <canvas id="canvas" width="500" height="300" style="border: 2px solid #000000"> </canvas> <script> // Initiate a canvas instance var canvas = new fabric.Canvas("canvas", { // UniformScaling is disabled uniformScaling: false }); // Creating an instance of the fabric.Rect class var circle = new fabric.Circle({ left: 70, top: 90, radius: 40, fill: "#006400", }); // Adding it to the canvas canvas.add(circle); </script> </body> </html>Output
<!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> <div style="padding: 10px; font-weight: bold; margin-left: 32px"> How to disable uniform scaling in canvas using FabricJS? </div> <canvas id="canvas" width="500" height="300" style="border: 2px solid #000000"> </canvas> <script> // Initiate a canvas instance var canvas = new fabric.Canvas("canvas", { // UniformScaling is enabled uniformScaling: true }); // Creating an instance of the fabric.Rect class var circle = new fabric.Circle({ left: 70, top: 90, radius: 40, fill: "#006400", }); // Adding it to the canvas canvas.add(circle); </script> </body> </html>output
The above is the detailed content of How to disable unified scaling in canvas using FabricJS?. For more information, please follow other related articles on the PHP Chinese website!