q5xjs icon indicating copy to clipboard operation
q5xjs copied to clipboard

Parent Container not working as expected

Open neelr opened this issue 4 years ago • 3 comments

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

neelr avatar Oct 06 '20 23:10 neelr

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!

LingDong- avatar Oct 07 '20 05:10 LingDong-

.parent() is definitely a useful thing!

Badokas avatar Oct 15 '20 18:10 Badokas

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

quinton-ashley avatar Feb 08 '23 22:02 quinton-ashley