Restrict orbit controls to part of the webpage

Hi,

I’ve added a small and simple 3D scene to only a part of my website, and everything worked. Then I wanted to add orbit controls to it but then I can’t scroll my webpage anymore. I’m wondering what I’m doing wrong since I’ve specified a particular domElement for the controls.

this is my code.

        var camera, scene, renderer, controls;
        var geometry, material, mesh;

        init();
        animate();

        function init() {

            camera = new THREE.PerspectiveCamera( 70, window.innerWidth / 600, 0.01, 10 );
            camera.position.z = 1;

            controls = new THREE.OrbitControls( camera );
		    controls.target.set( 0, 100, 0 );
            controls.update();

            scene = new THREE.Scene();

            geometry = new THREE.BoxGeometry( 0.2, 0.2, 0.2 );
            material = new THREE.MeshNormalMaterial();

            mesh = new THREE.Mesh( geometry, material );
            scene.add( mesh );
            scene.background = new THREE.Color( 0xffffff );

            renderer = new THREE.WebGLRenderer( { antialias: true } );
            renderer.setSize( window.innerWidth, 600 );
            $( "#3dArea" ).append(renderer.domElement);

            controls.domElement = $( "#3dArea" );

        }

        function animate() {

            requestAnimationFrame( animate );

            mesh.rotation.x += 0.01;
            mesh.rotation.y += 0.02;

            renderer.render( scene, camera );

        }

Check the docs, this is explained quite well there:

https://threejs.org/docs/#examples/controls/OrbitControls.domElement

1 Like