Fabric.js object: selected, no object selected

Using Fabric.js I am working with a text object, which I called a heading. When the title bar is selected, the div disappears with two input fields that can be used to set text and fill. This works for me.

What I'm trying to process further is when you delete the header object, I will disappear from my div. What is the correct way to handle header.off ()?

header.on('selected', function() {

  $('#header-text-edit').fadeIn('fast');

  // watch for header.input changes
  scope.$watch("header.input", function(value) {
    header.text = scope.header.input;
  });

  // watch for header.color changes
  scope.$watch("header.color", function(value) {
    header.fill = scope.header.color;
  });
});
+4
source share
2 answers

You need:

canvas.on('selection:cleared', function() {
  ...
});

Take a look at the "Events" and the "Events" section in the tutorial.

+11
source

branchjs 2.0 branch :

canvas.on('selection:created', function () {
   //...
});

canvas.on('selection:cleared', function () {
   //...
});

selected

var rect = new fabric.Rect({ width: 100, height: 50, fill: 'green' });
rect.on('selected', function() {
    console.log('selected a rectangle');
});
0

All Articles