gazman99
gazman99

Reputation: 41

fabric.js canvas.on('mouse:down')

Im drawing elements to a new fabric.js canvas. Im using the following code to listen to click events

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

  if (options.target) {
     //get details of element
     var clicked_id= options.target.get('id')

     //before hide or move logs:
     //options -> Object {target: u, e: MouseEvent}

     //after hide or move logs:
     //options -> Object {target: undefined, e: MouseEvent}

  }

});

The problems comes, when I hide or move an element. The options parameter within the callback function doesn't recognize that the click X,Y was on top of an element, even if I do a canvas.renderall() call.

The only way I can get around this is to initize the canavs object again.

any ideas?

Upvotes: 1

Views: 8009

Answers (1)

Yogesh
Yogesh

Reputation: 150

Call canvas.calcOffset(); after move and render

If it didn't work then try .setCoords();

Upvotes: 1

Related Questions