gpt4 book ai didi

javascript - 为什么使用 Aframe v0.5.0 时 DOM 没有通过 setAttribute 更新?

转载 作者:行者123 更新时间:2023-11-28 17:56:23 25 4
gpt4 key购买 nike

我要设置aframe-v0.5.0 <a-box>位置和颜色,并且它在浏览器中呈现正确,但是当我使用 box.getAtrribute("position") 时,它返回“未定义”,然后我发现 <a-box> positon 属性是 DOM 中显示的空字符串(缩放/旋转情况相同):

<a-box width="1" geometry="" height="1" depth="1" color="#0cf" material="" position="" rotation="" scale="" visible=""></a-box>

所以我切换回aframe-v0.2.0,一切正常!无法从谷歌得到任何答案,aframe-v0.5.0 中是否发生了变化?下面是我的代码,aframe.js 放在 <head> 中,我的脚本放在 <body> 中.

var body = document.body;
var scene = document.createElement("a-scene");
var camera = document.createElement("a-entity");
camera.setAttribute("camera", "userHeight: 1.6");
camera.setAttribute("look-controls", "");
camera.setAttribute("wasd-controls", "");
var box = document.createElement("a-box");
box.setAttribute("width", 1);
box.setAttribute("height", 1);
box.setAttribute("depth", 1);
box.setAttribute("color", "#0cf");
box.setAttribute("position", "0 0 -5");
scene.appendChild(camera);
scene.appendChild(box);
body.appendChild(scene);

console.log( box.getAttribute("position") ) //"undefined"

这里的例子: http://minicg.com/demo/aframe050_test/

最佳答案

https://aframe.io/docs/0.5.0/introduction/faq.html#why-is-the-html-not-updating-when-i-check-the-browser-inspector

If you open up your browser’s developer tools, you’ll see that the HTML attribute values are empty.

To improve performance, A-Frame does not update the HTML to save on stringification operations. Use the debug component or .flushToDOM methods if you need to sync to the DOM.

关于javascript - 为什么使用 Aframe v0.5.0 时 DOM 没有通过 setAttribute 更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44351745/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com