简体   繁体   中英

threejs: how to set renderer size to fit screen?

Using code below I have some problems:

        //WebGL renderer
        renderer = new THREE.WebGLRenderer();
        renderer.setSize(window.innerWidth, window.innerHeight); //TODO: set optimal size   
        document.body.appendChild(renderer.domElement);

Top left corner - some thin white border:

在此处输入图片说明

Bottom right corner - scroll elements (looks like window.innerWidth, window.innerHeight is bigger then initial view):

在此处输入图片说明

How to get w,h for renderer.setSize to fit all visible area inside window? Or maybe this problems should be fixed in other way?

the white space at the top and left is because I think the body has a margin by default.
The scrollbars are because for reasons unknown to me, the canvas element behaves as if it is an inline element.

This css should fix it:

body {
  margin: 0px;
  overflow: hidden;
}
canvas {
  display: block;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM