gpt4 book ai didi

javascript - 在fabric.js中多次设置defaultCursor

转载 作者:行者123 更新时间:2023-12-02 15:21:54 26 4
gpt4 key购买 nike

我可以设置canvas.defaultCursor,但一旦设置就无法将其更改为其他内容。这可能吗?

这是我的代码:

var canvas = new fabric.Canvas('c');

function setCursor(cursorType) {
if (cursorType == 'move') {
canvas.defaultCursor = 'move';
} else if (cursorType == 'crosshair') {
console.log('Changing cursor to crosshair'); // this works
canvas.defaultCursor = 'crosshair'; // this doesn't work
}
}

setCursor('move'); // this works

// ...

setCursor('crosshair');

最佳答案

我认为这种改变没有任何问题。查看此 fiddle 中的光标:

http://jsfiddle.net/v1nmtz02/4/

或者尝试这里的代码片段:

  var canvas = new fabric.Canvas('canvas');
function changeCursor(cursorType) {
canvas.defaultCursor = cursorType;
}
<script src="http://fabricjs.com/lib/fabric.js"></script>
<button onclick="changeCursor('crosshair');">crosshair</button>
<button onclick="changeCursor('move');">move</button>
<button onclick="changeCursor('default');">default</button>
<canvas id='canvas' width="550" height="550" style="border:#000 1px solid;"></canvas>

关于javascript - 在fabric.js中多次设置defaultCursor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33976103/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com