找回密码
 立即注册

QQ登录

只需一步,快速开始

Deunan

注册会员

5

主题

14

帖子

61

积分

注册会员

积分
61
Deunan
注册会员   /  发表于:2024-4-18 10:01  /   查看:479  /  回复:3
3金币
各位大佬,请问在网页js代码中document.getElementById("3dAnime").appendChild(xxxx
);到活字格js中应该如何改写?在活字格中我如何能拿到页面上的元素?页面上的元素是否支持appendChild操作?
以下为源码


<html><head>    <meta charset="utf-8">    <title>My first three.js app</title>    <style>        body {            margin: 0;        }    </style></head><body>    <!-- 网页布局 -->    <div style="float: left;display: block; margin: 0;padding: 0; width: 50; height: 720;background-color: aqua;">        <p style="margin: 0;padding: 0;font-size: 30px;color: black;">侧边栏宽50</p>    </div>    <div id="3dAnime" style="float: left;display: block; margin: 0;padding: 0; width: 1280; height: 720;"></div>     <!-- 动画 -->    <script src="Three/three.min.js"></script>    <script>        const scene = new THREE.Scene();        const camera = new THREE.PerspectiveCamera(75, 1280 / 720, 0.1, 1000);         const renderer = new THREE.WebGLRenderer();        renderer.setSize(1280, 720);        document.getElementById("3dAnime").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;         function animate() {            requestAnimationFrame(animate);             cube.rotation.x += 0.01;            cube.rotation.y += 0.01;             renderer.render(scene, camera);        };         animate();    </script></body> </html>

最佳答案

查看完整内容

参考这个的写法

3 个回复

倒序浏览
最佳答案
最佳答案
妄想社成员活字格认证
高级会员   /  发表于:2024-4-18 10:01:46
来自 2#


参考这个的写法

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
Deunan
注册会员   /  发表于:2024-4-18 17:58:11
3#

谢谢大佬,给大佬磕头了
回复 使用道具 举报
Shawn.Liu活字格认证
超级版主   /  发表于:2024-4-19 09:42:14
4#
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部