使用fabricjs创建图像对象。我们可以通过创建一个实例来创建一个图像对象fabric.image。由于它是fabricjs的基本元素之一,我们也可以很容易地通过应用属性,如角度、不透明度等,来自定义它。为了禁用多个特定控制点的图像对象,我们使用setcontrolsvisibility方法语法setcontrolsvisibility(options: object): fabric.object
参数options − 此参数接受一个 object 值,用于设置可见状态的控件。可能的值为−
‘tl’ − 此属性接受一个布尔值,用于启用或禁用左上角控件
‘tr’ −此属性接受一个布尔值,用于启用或禁用右上角控制
‘br’ −此属性接受一个布尔值,用于启用或禁用右下角控制‘bl’ - 这个属性接受一个布尔值,用于启用或禁用左下角控制‘ml’ − 此属性接受一个布尔值,用于启用或禁用中间左侧控制
‘mt’ −此属性接受一个布尔值,用于启用或禁用中上控制
‘mr’ −该属性接受一个布尔值,用于启用或禁用中右控制‘mb’ −该属性接受一个布尔值,用于启用或禁用中下控制
‘mtr’ −该属性接受一个布尔值,用于启用或禁用中上旋转控件
使用 setcontrolsvisibility 方法example让我们看一个代码示例,看看在setcontrolsvisibility方法被调用时的输出结果使用。 setcontrolsvisibility 方法设置多个指定控件的可见性。在在这种情况下,由于我们将“tl”和“bl”控件设置为false值,因此左上角并且底部左侧的控件将被禁用。
<!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>using setcontrolsvisibility method</h2> <p> you can select the image object to see that the bottom-left and top-left controls have been disabled </p> <canvas id=canvas></canvas> <img src=https://www.tutorialspoint.com/images/logo.png id=img1 style=display: none /> <script> // initiate a canvas instance var canvas = new fabric.canvas(canvas); canvas.setwidth(document.body.scrollwidth); canvas.setheight(250); // initiating the image element var imageelement = document.getelementbyid(img1); // initiate an image object var image = new fabric.image(imageelement, { top: 50, left: 110, }); // add it to the canvas canvas.add(image); // using setcontrolsvisibility method image.setcontrolsvisibility({ tl: false, bl: false, }); </script></body></html>
使用setcontrolsvisibility方法来禁用中间顶部旋转control的翻译为:controlexample在这个例子中,我们将使用setcontrolsvisibility方法来禁用“mtr”控件这也被称为中上旋转控制。
<!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> using setcontrolsvisibility method to disable the middle-top-rotate control </h2> <p> you can select the image object to see that the middle-top-rotate control has been disabled </p> <canvas id=canvas></canvas> <img src=https://www.tutorialspoint.com/images/logo.png id=img1 style=display: none /> <script> // initiate a canvas instance var canvas = new fabric.canvas(canvas); canvas.setwidth(document.body.scrollwidth); canvas.setheight(250); // initiating the image element var imageelement = document.getelementbyid(img1); // initiate an image object var image = new fabric.image(imageelement, { top: 50, left: 110, }); // add it to the canvas canvas.add(image); // using setcontrolsvisibility method image.setcontrolsvisibility({ mtr: false, }); </script></body></html>
以上就是如何使用fabricjs禁用图像对象的多个特定控制点?的详细内容。
