【发布时间】:2021-09-09 15:55:49
【问题描述】:
我的网站有一些通过three.js 的JS 代码。我希望两个画布使用单独的 CSS 命令(一个是 {position:relative} ;另一个是 {position:fixed} )用于不同的选项卡。但它抛出了那个错误。为什么?请帮帮我。
HTML 代码;
<canvas id="c1"></canvas>
<canvas id="c2"></canvas>
JS 代码; c1>
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.z = 30;
// camera.position.x = -15;
const canvas = document.querySelector('#c1');
const renderer = new THREE.WebGLRenderer({canvas, alpha: true});
renderer.setSize( window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
window.addEventListener('resize', function(){
var width = window.innerWidth;
var height = window.innerHeight;
renderer.setSize( width, height);
camera.aspect = width/height;
camera.updateProjectionMatrix();
})
//c2的代码与c1相同。
CSS;
#c1{
width: 100%;
height: 100vh;
position:relative;
z-index:1;
} //same c2
【问题讨论】:
标签: javascript html three.js