在本教程中,我們將使用 FabricJS 創(chuàng)建一個(gè)帶有等待光標(biāo)移動(dòng)對(duì)象的三角形。 wait 是可用的本機(jī)光標(biāo)樣式之一,也可以在 FabricJS 畫布中使用。 FabricJS 提供了各種類型的光標(biāo),例如默認(rèn)、全滾動(dòng)、十字準(zhǔn)線、列調(diào)整大小、行調(diào)整大小等,它們?cè)谀缓笾赜昧吮緳C(jī)光標(biāo)。
moveCursor 屬性設(shè)置當(dāng)對(duì)象在畫布中移動(dòng)時(shí)光標(biāo)的樣式。
語法
new fabric.Triangle({ moveCursor: String }: Object)
登錄后復(fù)制
參數(shù)
選項(xiàng)(可選) – 此參數(shù)是一個(gè)對(duì)象 為我們的三角形提供額外的定制。使用此參數(shù),可以更改與 moveCursor 為屬性的對(duì)象相關(guān)的屬性,例如顏色、光標(biāo)、描邊寬度和許多其他屬性。
選項(xiàng)鍵
moveCursor – 該屬性接受一個(gè)字符串,它允許我們?cè)O(shè)置在畫布上移動(dòng)此三角形對(duì)象時(shí)的默認(rèn)光標(biāo)值。該值決定移動(dòng)畫布對(duì)象時(shí)使用的光標(biāo)類型。
示例 1
對(duì)象移動(dòng)時(shí)的默認(rèn)光標(biāo)值在畫布上移動(dòng)
默認(rèn)情況下,當(dāng)我們?cè)诋嫴贾袊@三角形對(duì)象移動(dòng)時(shí),光標(biāo)類型是移動(dòng)。讓我們看一個(gè)代碼示例來理解這一點(diǎn)。
<!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 cursor value when object is moved around the canvas</h2> <p>You can move around the triangle to see that the default cursor type is "move"</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 triangle object var triangle = new fabric.Triangle({ left: 105, top: 75, width: 90, height: 80, fill: "#eedc82", stroke: "#bcb88a", strokeWidth: 5, }); // Add it to the canvas canvas.add(triangle); </script> </body> </html>
登錄后復(fù)制
示例 2
將 moveCursor 屬性作為鍵傳遞給值
在此示例中,我們將 moveCursor 鍵傳遞給三角形類值為“等待”。這將確保當(dāng)我們?cè)诋嫴贾械膶?duì)象周圍移動(dòng)時(shí),光標(biāo)值處于等待狀態(tài)。下面的代碼示例對(duì)此進(jìn)行了說明。
<!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 the moveCursor property as key with a value</h2> <p>You can move around the triangle to see that the cursor type is "wait"</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 triangle object var triangle = new fabric.Triangle({ left: 105, top: 75, width: 90, height: 80, fill: "#eedc82", stroke: "#bcb88a", strokeWidth: 5, moveCursor: "wait", }); // Add it to the canvas canvas.add(triangle); </script> </body> </html>
登錄后復(fù)制
以上就是如何使用 FabricJS 在移動(dòng)對(duì)象上創(chuàng)建帶有等待光標(biāo)的三角形?的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注www.92cms.cn其它相關(guān)文章!