简体   繁体   English

Fabric.js - 如何在没有绘图模式的情况下使用自定义光标

[英]Fabric.js - how to use custom cursors without drawing mode

I have no idea how to set up cursor image for drawing on the Canvas.我不知道如何设置用于在 Canvas 上绘图的光标图像。 I have noticed that I can set it only when我注意到我只能在

FABRICCANVAS.isDrawingMode = true;

However, the problem is that I have created dedicated drawing tools and I don't want to use those that are built into the Fabric.js.然而,问题是我已经创建了专用的绘图工具,我不想使用那些内置在 Fabric.js 中的工具。

Sample of my code (which doesn't work properly):我的代码示例(无法正常工作):

const FABRICCANVAS = new fabric.Canvas('canvas-draft');
const DRAFT = document.querySelector(".upper-canvas");
button.addEventListener('click', () => {
    DRAFT.style.cursor = 'url(img/cursors/image.png) 0 34, auto';
});

But when I set isDrawingMode to true, it works.但是当我将isDrawingMode设置为 true 时,它​​就起作用了。 Unfortunately, I don't want to use built-in drawing tools because they leave paths (that can then be moved later, when FABRICCANVAS.selection = true ).不幸的是,我不想使用内置绘图工具,因为它们会留下路径(然后可以在FABRICCANVAS.selection = true时移动)。

Do you know any solution for this problem?你知道这个问题的任何解决方案吗?

For the Canvas you can set different cursors:对于画布,您可以设置不同的光标:

eg例如

canvas.hoverCursor
canvas.defaultCursor
canvas.moveCursor

You can use absolute or relative paths to your cursor image:您可以使用光标图像的绝对或相对路径:

canvas.moveCursor = 'url("...") 10 10, crosshair';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM