Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ThreeJS - How to output canvas into specific div?

It seems that the canvas is simply inserted into the body, at the bottom of the flow. I was wondering which bit of code do I need to change to get it to insert into a specific div?

like image 418
styke Avatar asked Dec 01 '25 09:12

styke


2 Answers

It is usually this line:

container = document.createElement( 'div' );

//later in that file
container.appendChild( renderer.domElement );

change the first line to:

container = document.getElementById( 'mycustomdiv' );
like image 58
EliSherer Avatar answered Dec 03 '25 00:12

EliSherer


You could create the canvas yourself and put it to your desired location. Then pass it to the renderer constructor like this: renderer = new THREE.WebGLRenderer({ canvas: myCanvasElem }); See the docs.

like image 26
Tapio Avatar answered Dec 02 '25 23:12

Tapio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!