Daniele Sassoli
Daniele Sassoli

Reputation: 898

fabricjs set image as background

I'm looking for a way for placing an object permanently to the back of the canvas. I see that the various

canvas.sendBackwards(myObject)
canvas.sendToBack(myObject)

will send the object to the back of the canvas but if I add a new element and then send it backwards it will go beneath the other image and I need to avoid this. I cannot use canvas.setBackgroundImage because I'm creating a custom image class and setting it as backgroundImage will make me loose some functionality. I would like to set something like a z-index on the newly created image. For example, while initializing a new image I can set lockMovementX (and many others) to false or true, isn't there nothing like this for z-index of every canvas element, or do I have to push my background element to the back every time there's a change on the canvas?

Upvotes: 3

Views: 870

Answers (1)

PromInc
PromInc

Reputation: 1233

I've run into the same situation - I want an image as a background layer yet don't want to apply it as a background image due to restricted functionality.

I did write a function for my application that re-stacks layers every-time there is new layer added. I set the name attribute to this layer so I could quickly identify what layer it is that needs to be sent to the back.

While this may seen inefficient, I've never had any performance issues related to this function. But also in my application I typically only have about 5 to 20 layers - typically on the lower end of that range.

Upvotes: 2

Related Questions