-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
FAQ
kangax edited this page Jun 2, 2011
·
32 revisions
canvas.getObjects()
returns an array of all objects on canvas.
canvas.item(n)
returns n-th object on canvas (where indexing is associated with z-order)
canvas.getObjects(); // [...]
canvas.item(0); // first item
canvas.item(1); // second item
Using fabric.Object#set
method or one of the set* methods — setFill
, setWidth
, setHeight
, setOpacity
, etc.
rect.set('width', 100).set('height', 50);
// or
rect.set({ width: 100, height: 50 });
// or
rect.setFill('red');
rect.setOpacity(0.5);
Using "backgroundColor" property of fabric.Element
instance.
canvas.backgroundColor = 'red';
// or
canvas.backgroundColor = rgba(0, 255, 0, 0.5);
Using "clipTo" property of fabric.Element
instance:
canvas.clipTo = function(ctx) {
ctx.arc(0, 0, 60, 0, Math.PI*2, true);
};
// or passing to fabric.Element options
new fabric.Element('myCanvas', {
clipTo: function(ctx) {
ctx.arc(0, 0, 60, 0, Math.PI*2, true);
}
});
Using "shortcut" method clear()
of fabric.Element
instance:
canvas.clear(); // removes all objects and redraws a canvas area