5

我正在使用 Three.js。拥有一个包含两个 div 元素的 html 站点,是否可以仅在一个 div 元素中呈现?

HTML 代码:

<body>
    <div id="twocols">
        <div id="detailinfo">
            <span class="c">Detailinformationen:</span><br/>
            <span id="tb" class="g"></span><br/>
            <span class="c">Grafiken:</span>
            <div id="chart"></div>
            <div id="chart2"></div>
        </div>
        <div id="city">
        </div>                  
    </div>      
</body> 

我想渲染到城市 div。

三.js代码:

function initScene() {

            //container = document.createElement('div');
            //document.body.appendChild(container);

            scene = new THREE.Scene();
            createCamera();
            createLight();
            createProjector();
            createRenderer();
            createControls();

            //...
        }

创建渲染器:

function createRenderer() {
            renderer = new THREE.WebGLRenderer({
                antialias : ANTIALIAS, 
                preserveDrawingBuffer : DRAWINGBUFFER
            });

            renderer.setSize(document.getElementById("city").offsetWidth, document.getElementById("city").offsetHeight);
            document.getElementById("city").appendChild(renderer.domElement);

            THREEx.Screenshot.bindKey(renderer); // add the printscreen shortcut with "p"
        }

创建控件:

function createControls() {
            controls = new InteractionManager(camera, document.getElementById("city"));
            //...
        }

交互管理器.js

initialize: function(camera, domElement) {

    this.object = camera;
    this.domElement = (domElement !== undefined) ? domElement : document;
    this.target = new THREE.Vector3( 0, 0, 0 );
    //this.chartManager = new ChartsManager();

    if ( this.domElement === document ) {
        this.viewHalfX = window.innerWidth / 2;
        this.viewHalfY = window.innerHeight / 2;
    } else {
        this.viewHalfX = this.domElement.offsetWidth / 2;
        this.viewHalfY = this.domElement.offsetHeight / 2;
        //alert(domElement.offsetWidth + "  " + domElement.offsetHeight);
        //this.domElement.setAttribute( 'tabindex', -1 );
    }

    //...
},

至今..

4

1 回答 1

3

代替:

container = document.createElement('div');

利用:

container = document.getElementById('city');
于 2012-04-27T07:24:42.870 回答