Setting FabricJS Canvas Dimensions with Buttons
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

I have a responsive FabricJS canvas and I'm wondering if it's possible to "toggle", for the lack of a better word, the dimensions from "fluid" to being a square.

Here is what I have currently:

How might I achieve this? Please let me know if I can answer any questions that will help you produce a solution.



awarded to quillford

Crowdsource coding tasks.

1 Solution

Winning solution

here you go. this just finds which dimension, width or height, is smaller and makes that the size of the side of the square.

i added a variable so that it the fluid/square selection will persist after resizing.
quillford 20 days ago
here's the link for that
quillford 20 days ago
This looks great, thanks! Would you be interested in tinkering with it further for a tip? I'm interested in having it remain square if the window is resized (if it was set to square), but fluid if the window is resized (if it's set to fluid, the default). Thanks again
sharper 20 days ago
this should do it
quillford 20 days ago
Looks great, thank you
sharper 20 days ago