如何在没有鼠标点击的情况下触发'对象:选中'?

时间:2017-03-22 01:36:44

标签: javascript fabricjs

我正在使用fabric js canvas。我需要在不点击对象或画布的情况下触发'object:selected'。我试着打电话给以下人员:

canvas._handleEvent('mouse:down','object:selected', Myobject);

我尝试将收到的事件设为'mouse:down',并将事件设为'object:selected'。但它说"canvas._handleEvent is not a function"。 有什么建议吗?

1 个答案:

答案 0 :(得分:0)

这应该这样做:



var canvas = new fabric.Canvas('canvas');
canvas.on('object:selected', function(e) {
  alert('object:selected fired');
});
canvas.trigger('object:selected');

<script src="//cdnjs.cloudflare.com/ajax/libs/fabric.js/1.4.0/fabric.min.js"></script>
<canvas tabindex="1" id="canvas" width="10" height="10"></canvas>
&#13;
&#13;
&#13;

更多信息:https://github.com/kangax/fabric.js/wiki/Working-with-events