2023如何使用 FabricJS 创建带有不允许的光标的画布?

 所属分类:web前端开发

 浏览:51次-  评论: 0次-  更新时间:2023-09-22
描述:更多教程资料进入php教程获得。 在本文中,我们将使用 FabricJS &#...
更多教程资料进入php教程获得。

如何使用 FabricJS 创建带有不允许的光标的画布?

在本文中,我们将使用 FabricJS 创建一个带有不允许的光标的画布。不允许的游标可用于指示不会执行已请求的任何操作。 not-allowed 是可用的原生光标样式之一,也可以在 FabricJS 画布中使用。

FabricJS 提供各种类型的光标,如默认、全滚动、十字准线、列调整大小、行调整大小等等,它们正在重用本机光标底层。根据操作系统的不同,每个游标看起来都略有不同。

语法

new fabric.Canvas(element: HTMLElement|String, { defaultCursor: String }: Object)

参数

  • 元素 - 此参数是 em> 元素本身,可以使用 document.getElementById() 元素本身的 id 派生。 FabricJS 画布将在此元素上初始化。

  • 选项(可选) - 此参数是一个对象,它提供对我们的画布进行额外的定制。使用这个参数可以改变画布相关的颜色、光标、边框宽度等很多属性,其中defaultCursor是一个属性,通过它我们可以设置我们想要的光标类型。

示例 1

defaultCursor 属性接受一个字符串,该字符串确定要在画布上使用的光标的名称。我们将其设置为not-allowed,以使用不允许的游标。让我们看一个示例,在 FabricJS 中创建一个带有不允许的光标的画布。

<!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>Canvas with not-allowed cursor using FabricJS</h2>
   <p>Bring the cursor inside the canvas to see the changed shape of cursor</p>
   <canvas id="canvas"></canvas>
   <script>
      //Initiate a canvas instance
      var canvas = new fabric.Canvas("canvas", {
         defaultCursor: "not-allowed"
      });
      canvas.setWidth(document.body.scrollWidth);
      canvas.setHeight(250);
   </script>
</body>
</html>

示例 2

在此示例中,我们将在画布上添加一个圆圈以及不允许的光标

<!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>Canvas with not-allowed cursor using FabricJS</h2>
   <p>Here we have added a circle to the canvas along with the not-allowed cursor</p>
   <canvas id="canvas"></canvas>
   <script>
      //Initiate a canvas instance
      var canvas = new fabric.Canvas("canvas", {
         defaultCursor: "not-allowed"
      });
      // Initiate a Circle instance
      var circle = new fabric.Circle({
         radius: 50,
         fill: "green"
      });
      // Render the circle in canvas
      canvas.add(circle);
      canvas.setWidth(document.body.scrollWidth);
      canvas.setHeight(250);
   </script>
</body>
</html>
 标签:
积分说明:注册即送10金币,每日签到可获得更多金币,成为VIP会员可免金币下载! 充值积分充值会员更多说明»

讨论这个素材(0)回答他人问题或分享使用心得奖励金币

〒_〒 居然一个评论都没有……

表情  文明上网,理性发言!