A
A
Alexander Ka2017-04-20 14:16:45
JavaScript
Alexander Ka, 2017-04-20 14:16:45

Fabric.js How to handle a click on an object?

I read the article https://habrahabr.ru/post/162367/ several times.
I'm trying to figure out how to make a click on an object.
The example has a structure:

canvas.on('mouse:down', function(options) {
  if (options.target) {
    console.log('an object was clicked! ', options.target.type);
  }
});

But it processes all objects and only "path" is needed.
I couldn't think of anything better to do like this
var x ;
    canvas.on('mouse:down', function(options) {
       if (options.target) {
      
      x = options.target.type;
      if (x == 'path') { 
        console.log( x + ' is here');
       }
      }
    });

It doesn't work any other way, including:
path.on('mouse:down', function() {
      console.log('click in path');
      });

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question