Search code examples
javascriptobjectcanvasfabricjs

How can i manipulate all objects in fabricjs?


I am trying to set strokeWidth of all object in fabric js, but i cant find a way to manipulate all the objects on canvas, i tried creating a an array and pushing all items dropped on canvas to the array.


Solution

  • I think you can use .getObjects() method of canvas. I made an example for you here https://codesandbox.io/s/mystifying-curran-bkwtk?file=/src/index.js

    canvas.getObjects().forEach(obj => {
      obj.set({
        stroke: "brown",
        strokeWidth: 10
      });
    });