【发布时间】:2023-03-10 19:46:01
【问题描述】:
A-Frame 完全加载时是否会触发某些事件?现在我已经设法让我的document.querySelector(".a-enter-vr-button") 工作了,但只是在将它放在setTimeout 函数中之后,这似乎是一个临时的解决方案。因此,如果有人有任何方法在 A-Frame 完全加载后触发 js 脚本,请告诉我!
【问题讨论】:
标签: aframe
A-Frame 完全加载时是否会触发某些事件?现在我已经设法让我的document.querySelector(".a-enter-vr-button") 工作了,但只是在将它放在setTimeout 函数中之后,这似乎是一个临时的解决方案。因此,如果有人有任何方法在 A-Frame 完全加载后触发 js 脚本,请告诉我!
【问题讨论】:
标签: aframe
您可以使用loaded 事件:
document.querySelector('a-scene').addEventListener('loaded', function () {...})
但我们建议您使用组件,这样您就不必处理等待事件来进行设置:
AFRAME.registerComponent('log', {
schema: {type: 'string'},
init: function () {
var stringToLog = this.data;
console.log(stringToLog);
}
});
然后使用 HTML 中的组件:
<a-scene log="Hello, Scene!">
<a-box log="Hello, Box!"></a-box>
</a-scene>
【讨论】: