【发布时间】:2019-01-16 00:09:16
【问题描述】:
我需要使渲染器的大小适合网页上元素的大小。执行renderer.setSize(window.innerWidth, window.innerHeight) 将渲染器的大小设置为适合整个窗口。
init() {
let map = document.getElementById('map');
this.scene = new THREE.Scene();
this.scene.background = new THREE.Color( 0xf0f0f0 );
this.camera = new THREE.PerspectiveCamera(
75,
//window.innerWidth / window.innerHeight,
1341/958, //hardcoded for now, but needs to be automatic
0.1,
1000,
);
this.camera.position.z = 3;
this.renderer = new THREE.WebGLRenderer();
//this.renderer.setSize(window.innerWidth, window.innerHeight); // it should not be a whole window
this.renderer.setSize(1341,958); //hardcoded for now, but needs to be automatic
map.appendChild(this.renderer.domElement);}
预期:如果您取消注释 cmets,整个渲染器将占用整个窗口的大小。
实际:我必须自己对尺寸进行硬编码,但这只是一个修补程序:(
【问题讨论】:
-
map.style.height和map.style.width应该返回您需要的尺寸
标签: javascript html three.js