您好,欢迎访问一九零五行业门户网

如何使用FabricJS设置控制Textbox角的破折号图案?

在本教程中,我们将学习如何使用 fabricjs 实现控制 textbox 角点的虚线图案。对象的控制角允许我们缩放、拉伸或更改其位置。我们可以通过多种方式自定义控制角,例如为其添加特定颜色、更改其大小等。我们还可以使用 cornerdasharray 属性为控制角指定虚线图案。 p>
语法new fabric.textbox(text: string, { cornerdasharray: array }: object)
参数text - 此参数接受一个 string,这是我们想要的文本字符串显示在我们的文本框中。
选项(可选) - 此参数是一个对象,它为我们的文本框提供额外的自定义。使用此参数,可以更改与 cornerdasharray 为属性的对象相关的颜色、光标、描边宽度和许多其他属性等属性。
选项键cornerdasharray:此属性接受一个array,它允许我们指定控制角的虚线图案。例如,如果我们传递一个值为 [2,3] 的数组,则表示 2px 破折号和 3px 间隙的破折号图案,并且无限重复此图案。
示例 1控制角的默认外观
让我们看一个代码示例,它描述了文本框对象的控制角的默认外观。由于我们没有使用 cornerdasharray 属性,因此没有显示破折号图案。
<!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>default appearance of controlling corners</h2> <p>you can select the textbox to see the default appearance of controlling corners</p> <canvas id=canvas></canvas> <script> // initiate a canvas instance var canvas = new fabric.canvas(canvas); canvas.setwidth(document.body.scrollwidth); canvas.setheight(250); // initiate a textbox object var textbox = new fabric.textbox(how high you fly is derived from how big you think., { backgroundcolor: rgba(204,255,0,0.2), width: 400, top: 70, left: 110, cornercolor: #87a96b, }); // add it to the canvas canvas.add(textbox); </script></body></html>
示例 2将 cornerdasharray 属性作为键传递
在此示例中,我们向 cornerdasharray 属性传递值 [1,2,1]。这意味着将创建一个虚线图案,其中有一条 1 像素长的线,后面是 2 像素的间隙,然后再次绘制一条 1 像素长的线,之后将形成 1 像素的间隙,依此类推。
<!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>passing cornerdasharray property as key</h2> <p>you can select the textbox to see the dash pattern of controlling corners</p> <canvas id=canvas></canvas> <script> // initiate a canvas instance var canvas = new fabric.canvas(canvas); canvas.setwidth(document.body.scrollwidth); canvas.setheight(250); // initiate a textbox object var textbox = new fabric.textbox(how high you fly is derived from how big you think., { backgroundcolor: rgba(204,255,0,0.2), width: 400, top: 70, left: 110, cornercolor: #87a96b, cornerdasharray: [1, 2, 1], }); // add it to the canvas canvas.add(textbox); </script></body></html>
以上就是如何使用fabricjs设置控制textbox角的破折号图案?的详细内容。
其它类似信息

推荐信息