javascript - mouse:down vs. mousedown in fabric.js - Stack Overflow

Here is a fabric.js example with a canvas and a rectangle, with a mouse down handler on each:var canvas

Here is a fabric.js example with a canvas and a rectangle, with a mouse down handler on each:

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

var rect = new fabric.Rect({ 
  left: 100, 
  top: 100, 
  width: 50, 
  height: 50, 
  fill: '#faa', 
})

canvas.add(rect);

canvas.on('mouse:down', function(options) {
  console.log('canvas event');
});

rect.on('mousedown', function(options) {
  console.log('rect event');
});

Why does it need to be mouse:down on the canvas, but mousedown on the rectangle? If I change either, they stop working. Is the mousedown not actually a fabric event, and if so, should the handler function be different?

JsFiddle: /

Here is a fabric.js example with a canvas and a rectangle, with a mouse down handler on each:

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

var rect = new fabric.Rect({ 
  left: 100, 
  top: 100, 
  width: 50, 
  height: 50, 
  fill: '#faa', 
})

canvas.add(rect);

canvas.on('mouse:down', function(options) {
  console.log('canvas event');
});

rect.on('mousedown', function(options) {
  console.log('rect event');
});

Why does it need to be mouse:down on the canvas, but mousedown on the rectangle? If I change either, they stop working. Is the mousedown not actually a fabric event, and if so, should the handler function be different?

JsFiddle: http://jsfiddle/243kau3x/4/

Share asked Sep 29, 2015 at 10:09 Tor KlingbergTor Klingberg 5,1186 gold badges45 silver badges54 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

They are both fabric js events. The main difference is the type of instances to which the events are attached.
mouse:down is a event specific for the fabric Canvas instance while mousedown is specific to a fabric Object instance, in your case a rect.

There are different types of events that can be listened on a Canvas and on an Object instance. The full list of available events is available on fabric js official site.

The events specific to the Canvas instance are presented in detail on the library official GitHub page in this post.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744808070a4594899.html

相关推荐

  • javascript - mouse:down vs. mousedown in fabric.js - Stack Overflow

    Here is a fabric.js example with a canvas and a rectangle, with a mouse down handler on each:var canvas

    2天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信