![](/img/trans.png)
[英]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.