如何防止激活鼠标按下事件的功能

How to prevent activated mousedown event by function?

本文关键字:事件 功能 何防止 激活 鼠标      更新时间:2023-09-26
function itext(){
function addText() {
canvas.on('mouse:up', function(options) {
var left1=Math.round(options.e.clientX)-139;
var top1=Math.round(options.e.clientY)-250;
var newText = new fabric.IText("",{
    left:left1,
    top:top1
});
canvas.add(newText);
canvas.setActiveObject(newText);
newText.enterEditing();
newText.selectAll();
});
}
canvas.on('mouse:down', addText);
}

我想添加一些文本到画布上,当我点击画布。我用这个函数来做。执行此函数后,mouseevent应该被禁用。但我不知道如何防止激活鼠标事件。任何想法/例子将不胜感激。谢谢你。

e.PreventDefault这样的东西应该起作用它会阻止默认的点击动作表单通过所以你的函数应该每次点击只触发一次

在函数执行前设置布尔变量为false。然后你的函数检查它是否为真,如果为真,它什么也不做。如果为false,则按照您的要求执行,并将变量设置为true。这样它只执行一次。