
在本文中,我们将使用 FabricJS 创建一个带有不允许的光标的画布。不允许的游标可用于指示不会执行已请求的任何操作。 not-allowed 是可用的原生光标样式之一,也可以在 FabricJS 画布中使用。
FabricJS 提供各种类型的光标,如默认、全滚动、十字准线、列调整大小、行调整大小等等,它们正在重用本机光标底层。根据操作系统的不同,每个游标看起来都略有不同。
new fabric.Canvas(element: HTMLElement|String, { defaultCursor: String }: Object)元素 - 此参数是
选项(可选) - 此参数是一个对象,它提供对我们的画布进行额外的定制。使用这个参数可以改变画布相关的颜色、光标、边框宽度等很多属性,其中defaultCursor是一个属性,通过它我们可以设置我们想要的光标类型。
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>在此示例中,我们将在画布上添加一个圆圈以及不允许的光标
<!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>以上就是如何使用 FabricJS 创建带有不允许的光标的画布?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号