在本教程中,我们将学习如何禁用图像的特定控制点使用 fabricjs 的对象。我们可以通过创建一个实例来创建一个 image 对象织物.图像。由于它是fabricjs的基本元素之一,我们也可以轻松地通过应用角度、不透明度等属性来自定义它。为了禁用特定的image 对象的控制点,我们使用 setcontrolvisible 方法。
语法setcontrolvisible(controlkey: string, visible: boolean): fabric.object
参数controlkey - 此参数接受一个 string 值,该值指定控制。可能的值是 -
'tl' - 此属性接受启用或禁用左上角控件的布尔值。'tr' - 该属性接受一个布尔值,用于启用或禁用右上角的控件。'br' - 此属性接受一个布尔值,用于启用或禁用右下角控件。'bl' - 此属性接受一个布尔值,用于启用或禁用左下角控件。'ml' - 此属性接受一个布尔值,用于启用或禁用中左控件。'mt' - 此属性接受一个布尔值,用于启用或禁用中顶部控件。'mr' - 此属性接受一个布尔值,用于启用或禁用右中控件。'mb' - 此属性接受一个布尔值,用于启用或禁用中下控件。'mtr' - 此属性接受一个布尔值,用于启用或禁用中上旋转控件。visible - 此参数接受一个 boolean 值,当“true”时设置指定控件在“false”的情况下可见和不可见。
使用setcontrolvisible方法示例让我们看一个代码示例,看看使用 setcontrolvisible 方法时的输出。setcontrolvisible 方法设置指定控件的可见性。在这种情况下,由于我们已将“br”控件传递给错误值,因此右下角的控件将不会不再可见。
<!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 setcontrolvisible method</h2> <p> you can select the image object to see that the bottom-right control is not visible </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 setcontrolvisible method image.setcontrolvisible(br, false); </script></body></html>
使用setcontrolvisible方法禁用中上旋转控制示例在此示例中,我们使用 setcontrolvisible 方法禁用“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 setcontrolvisible method to disable the middle-top-rotate control </h2> <p> you can select the image object to see that the middle-top-rotate control is not visible </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 setcontrolvisible method image.setcontrolvisible(mtr, false); </script></body></html>
以上就是如何使用 fabricjs 禁用 image 对象的特定控制点?的详细内容。