你如何使用 jquery 来改变框架中对象的位置?
How do you use jquery to change position of object in aframe?
我正在尝试使用 jquery attr() 移动一个框架球体。
我在脚本标签中使用了它(a 球体已经与 id 球体一起存在。):
var x = '0 5 0';
$("#sphere").attr('position', x);
没用。是否有不同的更改方法或我有误?
使用setAttribute
。更多信息见 A-Frame docs
$("#sphere")[0].setAttribute('position', {x: 1, y: 2, z: 3});
仅供参考,您还可以使用标准 DOM querySelector 而不是 jQuery
document.querySelector(“#sphere”).setAttribute('position', {x: 1, y: 2, z: 3});
如果仍然不起作用,我建议共享代码,人们可以 运行 和调试。 Glitch is great
我正在尝试使用 jquery attr() 移动一个框架球体。
我在脚本标签中使用了它(a 球体已经与 id 球体一起存在。):
var x = '0 5 0';
$("#sphere").attr('position', x);
没用。是否有不同的更改方法或我有误?
使用setAttribute
。更多信息见 A-Frame docs
$("#sphere")[0].setAttribute('position', {x: 1, y: 2, z: 3});
仅供参考,您还可以使用标准 DOM querySelector 而不是 jQuery
document.querySelector(“#sphere”).setAttribute('position', {x: 1, y: 2, z: 3});
如果仍然不起作用,我建议共享代码,人们可以 运行 和调试。 Glitch is great