[英]A-Frame: How do I add a button INSIDE of the a-scene tags that plays video on mobile?
[英]A-Frame dynamically add objects to a-scene (JS, Html)
我正在尝试使用 innerHTML 将元素添加到 a-scene 标记,以下代码不起作用。 我想用 Perlin Noise 3D 创造一个小世界我不想为我要渲染的每个块编写代码。 知道我怎样才能完成这项工作吗?
<html lang="en">
<head>
<title>A-Frame</title>
<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
<script src="https://unpkg.com/perlin-noise-3d"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script>
</script>
</body>
</head>
<body>
<a-scene id="scene">
</a-scene>
<script>
$("#scene").innerHTML = '<a-box position="-1 0.5 -3" rotation="0 45 0" color="#4CC3D9"></a-box>'
</script>
您需要通过document.createElement()
和 append 创建元素到带有parent.appendChild(node)
的场景中才能正常工作:
const scene = document.querySelector("a-scene"); const box = document.createElement("a-box"); box.setAttribute("color", "red"); box.setAttribute("position", "0 1 -3"); scene.appendChild(box);
<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script> <a-scene> </a-scene>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.