Greetings, I am in need of some assistance with a coding issue.
I have a for loop that generates and adds multiple rectangles to a fabric js canvas. To set a texture for each rectangle, I am using the following code snippet.
var rect = new fabric.Rect({
width: 100,
height: 100,
selectable: true,
hasControls: false,
borderColor: 'red',
borderWidth: 2,
lockMovementX: true,
lockMovementY: true
});
canvas.add(rect);
fabric.util.loadImage('construct/css/img/patterns/1.jpg', function(img) {
rect.set('fill', new fabric.Pattern({
source: img,
repeat: 'repeat'
}));
});
Execute
After running the code, only the last rectangle added has a texture applied, while the others do not.
This situation is truly frustrating me.
Any help on this matter would be greatly appreciated.
Thank you in advance.