Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fabricjs: How to change opacity when object is being resized or scaled?

Tags:

fabricjs

I want to set opacity of object to 0.5 when it is being moved/resized/scaled/drag.

We do have event handlers for all of them but they will be fired only once when any of these will start. I want to make object opacity=1 when activity is done.

like image 902
Maulik Gandhi Avatar asked Jun 27 '15 17:06

Maulik Gandhi


1 Answers

I think that you can use mouse:up event for that. And when mouse:up event fires you set the opacity to 1.

canvas.on('mouse:up', function(){
    var obj = canvas.getActiveObject();
    obj.set({
        opacity: 1
    });
    canvas.renderAll();
});

Here is a jsFiddle with an example with scaling.

like image 154
Nistor Cristian Avatar answered Nov 06 '22 06:11

Nistor Cristian