在本教程中,我們將學(xué)習(xí)如何使用 FabricJS 設(shè)置圓的 X 軸傾斜角度。圓形是 FabricJS 提供的各種形狀之一。為了創(chuàng)建一個(gè)圓圈,我們將創(chuàng)建一個(gè)fabric.Circle類的實(shí)例并將其添加到畫(huà)布中。我們的圓圈對(duì)象可以通過(guò)多種方式自定義,例如更改其尺寸,添加背景顏色或通過(guò)改變 X 軸上的傾斜角度。我們可以通過(guò)使用 skewX 屬性來(lái)做到這一點(diǎn)。
語(yǔ)法
new fabric.Circle({ skewX : Number }: Object)
登錄后復(fù)制
參數(shù)
選項(xiàng)(可選) – 此參數(shù)是一個(gè)對(duì)象 為我們的圈子提供額外的定制。使用此參數(shù),可以更改與 skewX 為屬性的對(duì)象相關(guān)的屬性,例如顏色、光標(biāo)、描邊寬度和許多其他屬性。
選項(xiàng)鍵
skewX – 此屬性接受數(shù)字,確定對(duì)象 X 軸上的傾斜角度。
示例 1
>當(dāng)不應(yīng)用 skewX 屬性時(shí)
讓我們看一個(gè)示例來(lái)了解當(dāng)不應(yīng)用 skewX 屬性時(shí)我們的圓形對(duì)象如何顯示。在這種情況下,我們的圓形對(duì)象不會(huì)出現(xià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>Setting the angle of skew on X-axis of circle using FabricJS</h2> <p>Here we have not applied the <b>skewX</b> property, hence there is no distortion in the object. </p> <canvas id="canvas"></canvas> <script> // Initiate a canvas instance var canvas = new fabric.Canvas("canvas"); var circle = new fabric.Circle({ left: 50, top: 90, radius: 50, fill: "#ccccff", stroke: "#7b68ee", strokeWidth: 5 }); canvas.add(circle); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); </script> </body> </html>
登錄后復(fù)制
示例 2
將 skewX 作為鍵傳遞并為其分配自定義值。
在此示例中,我們將了解如何分配skewX 屬性的數(shù)值。傳遞的值將確定沿 X 軸的扭曲。由于我們已將 skewX 屬性的值指定為 30,因此效果就好像圓形對(duì)象被水平捏過(guò)角以形成 30 度角。
<!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>Setting the angle of skew on X-axis of circle using FabricJS</h2> <p>Observe that the object is skewed on the X-axis in the clockwise direction at an angle of 30 degrees, as we have set <b>skewX</b> at 30. </p> <canvas id="canvas"></canvas> <script> // Initiate a canvas instance var canvas = new fabric.Canvas("canvas"); var circle = new fabric.Circle({ left: 50, top: 90, radius: 50, fill: "#ccccff", stroke: "#7b68ee", strokeWidth: 5, skewX: 30 }); canvas.add(circle); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); </script> </body> </html>
登錄后復(fù)制
以上就是如何使用 FabricJS 設(shè)置圓的 X 軸傾斜角度?的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注www.92cms.cn其它相關(guān)文章!