javascript - 如何将三个 js 对象居中到 DIV 中:
问题描述
我无法将三个 js 对象居中到 DIV
import * as THREE from 'https://cdn.skypack.dev/pin/three@v0.128.0-iDyvDZdRCoyR9DXa2rWg/mode=imports,min/optimized/three.js';
const container = document.getElementById("canvas");
// const selected = document.querySelector("#canvas");
// document.body.appendChild(container);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( container.offsetWidth, container.offsetWidth );
// renderer.setSize( item.clientWidth, item.clientHeight );
container.appendChild( renderer.domElement );
const geometry = new THREE.BoxGeometry();
const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
const cube = new THREE.Mesh( geometry, material );
scene.add( cube );
camera.position.z = 5;
const animate = function () {
requestAnimationFrame( animate );
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
renderer.render( scene, camera );
};
animate();
这就是问题的样子:
刚刚超出 DIV 的对象:
我不知道为什么会这样。我试图解决这个问题几天并尝试了很多方法,但它仍然不起作用。可能我不明白的东西,需要你的帮助......
解决方案
我想我解决了这个问题。我只是删除了css中#canvas的填充,它现在可以按预期工作。
推荐阅读
- c++ - 如何使用现代 CMake 安装捆绑的接口依赖项?
- angular - Angular 5 和原生 IOS/Android 通信
- perl - websocket异步反馈长流程
- java - 为什么 ForkJoinPool::invoke() 会阻塞主线程?
- sql - 如何避免联合所有
- javascript - $document.append($rootElement); null 不是对象(评估 context.createDocumentFragment)
- sql-server - 在 MSSQL 中将数据导出到类似 csv 的文件
- authentication - 关闭选项卡后,Vuex 持久状态不会删除状态
- cassandra - Cassandra 版本 3.11.2 计数器更新始终为空
- php - Laravel 中 Dingo API 中的 CORS 中间件