How to detect when a scene is loaded in A-Frame?

强颜欢笑 提交于 2019-11-29 14:36:05

You can use the loaded event:

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:

https://aframe.io/docs/0.4.0/guides/using-javascript-and-dom-apis.html#where-to-place-javascript-code-for-a-frame

AFRAME.registerComponent('log', {
  schema: {type: 'string'},
  init: function () {
    var stringToLog = this.data;
    console.log(stringToLog);
  }
});

Then to use the component from HTML:

<a-scene log="Hello, Scene!">
  <a-box log="Hello, Box!"></a-box>
</a-scene>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!