Skip to content

pass container width and height prop to createCanvas #338

Closed Answered by yevdyko
hanhanxue asked this question in Q&A
Discussion options

You must be logged in to vote

How about using JS to get the size of the container?

const container = document.getElementById("Container");

and after use

container.offsetHeight;
container.offsetWidth;

Then you can pass these values to the P5Canvas component and use them when creating a sketch.

In any case, your approach seems like over-engineering to me. I found some examples on stackoverflow of how to do this in plain JS, so try exploring the issue further. In my opinion, it has nothing to do with the need to pass values inside the wrapper. They should be calculated when the sketch is created.

Replies: 2 comments 9 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
9 replies
@yevdyko
Comment options

yevdyko Mar 24, 2024
Collaborator

@hanhanxue
Comment options

@hanhanxue
Comment options

@yevdyko
Comment options

yevdyko Mar 24, 2024
Collaborator

Answer selected by hanhanxue
@yevdyko
Comment options

yevdyko Mar 24, 2024
Collaborator

@yevdyko
Comment options

yevdyko Mar 24, 2024
Collaborator

@hanhanxue
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants