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 8 months ago
here's the link for that
quillford 8 months 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 8 months ago
this should do it
quillford 8 months ago
Looks great, thank you
sharper 8 months ago
Hi again Quillford, would you be interested in adding functionality so that I may type in my desired dimensions as well? I'd be willing to tip the same amount as this bounty if you are!
sharper 4 months ago