我正在玩three.js和bootstrap。但是,使用引導網格的時候,我的立方體被夷爲平地這樣的:Three.js渲染和自舉網格
雖然調整窗口大小時,它工作正常:
我曾試圖解決這個問題CSS,但它沒有工作:
CSS
@media(min-width:768px) {
canvas {
display: block;
width: 100% !important;
height: 33% !important;
}
}
canvas {
display: block;
width: 100% !important;
height: 100% !important;
}
任何想法?
編輯:
我也試圖與JS代碼的工作,也沒有任何結果:
JS:
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.getElementById('render').appendChild(renderer.domElement);
window.addEventListener('resize', onWindowResize, false);
render();
}
function onWindowResize() {
if (window.matchMedia('(min-width:768px)').matches) {
renderer.setSize(window.innerWidth, window.innerHeight * 0.33);
camera.updateProjectionMatrix();
camera.aspect = window.innerWidth/window.innerHeight;
render();
}
else {
camera.aspect = window.innerWidth/window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
render();
}
}
同樣的想法,但無法獲得風格注入的JavaScript ... – PLAYCUBE
我不知道你的意思是「無法將樣式轉換爲javascript」 – 2pha
謝謝你,thanks愛你的幫助!有一個很好的解決方案[這裏](http://stackoverflow.com/questions/38789139/css-how-to-set-the-width-and-height-dependent-on-the-screen-window-size);) – PLAYCUBE