LingDong- / q5xjs

A small and fast alternative (experimental) implementation of p5.js
https://q5xjs.netlify.app/
The Unlicense
541 stars 25 forks source link

Parent Container not working as expected #7

Open neelr opened 3 years ago

neelr commented 3 years ago

How would you put it in a parent div?

q5.createCanvas(width, height).parent(
    "div-id-or-element"
);

returns an error of can't find parent of null

LingDong- commented 3 years ago

Hi @neelr ,

Currently you can use q5.canvas to get the canvas HTML element, and put it under new parent using the usual JS way:

let parent = document.getElementById("div-id");
parent.appendChild(q5.canvas);

But I do think the .parent() wrapper is nice, so I'm considering adding the feature soon. Thanks for reporting!

Badokas commented 3 years ago

.parent() is definitely a useful thing!

quinton-ashley commented 1 year ago

I won't implement .parent() because technically its bad practice because it causes a CLS https://web.dev/cls/

But I did implement adding the parent element as a parameter to the instance constructor!

let q = Q5(parentElem);

https://github.com/quinton-ashley/q5js