Jung
Jung

Reputation: 207

fabric canvas make my 1st object always unselectable

var json = '{"objects":
[{"type":"rect","originX":"center","originY":"center","left":300,"top":150,"width"
:150,"height":150,"fill":"#29477F","overlayFill":null,"stroke":null,"strokeWidth":
1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMi
terLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity"
:1,"shadow":{"color":"rgba(94, 128, 191, 0.5)","blur":5,"offsetX":10,"offsetY":10},"visible":true,"clipTo":null,"rx":0,"ry"
:0,"x":0,"y":0}

my json contain 2 object and my intention is to make the 1st object always delectable / unmovable , how is going to achieve this ? here is what i tried and i need to use loadFromJSON.

var objectx = canvas.getObjects().length; //get all object length;
objectx[1].selectable = false; //make object unselectable;

here is my DEMO

Upvotes: 0

Views: 431

Answers (1)

AndreaBogazzi
AndreaBogazzi

Reputation: 14731

Lowest object unselectable:

var objectx = canvas.getObjects();
objectx[0].selectable = false;

highest object unselectable:

var objectx = canvas.getObjects();
objectx[objectx.length - 1].selectable = false;

This should do the trick.

Upvotes: 1

Related Questions