如何检测场景何时加载到A帧中? [英] How to detect when a scene is loaded in A-Frame?
问题描述
完全加载A帧时是否会触发某些事件?现在,我已经设法使我的 document.querySelector(。a-enter-vr-button)
工作,但只有将它放在 setTimeout
函数,这似乎是一个临时解决方案。因此,如果有人在A-Frame完全加载后可以使js脚本启动,请告诉我!
Is there some event that is triggered when A-Frame is fully loaded? Right now I’ve managed to get my document.querySelector(".a-enter-vr-button")
working, but only after placing it inside a setTimeout
function, which seems a bit of a makeshift solution. So if anyone has any way of making a js script fire after A-Frame has fully loaded please let me know!
推荐答案
您可以使用 loaded
事件:
document.querySelector('a-scene') .addEventListener('loaded',function(){...})
但是我们建议您使用组件,因此您不必处理事件等待设置的事情:
But we recommend using components so you don't have to handle waiting on events for things to get set up:
AFRAME.registerComponent('log', {
schema: {type: 'string'},
init: function () {
var stringToLog = this.data;
console.log(stringToLog);
}
});
然后使用HTML中的组件:
Then to use the component from HTML:
<a-scene log="Hello, Scene!">
<a-box log="Hello, Box!"></a-box>
</a-scene>
这篇关于如何检测场景何时加载到A帧中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!