【问题标题】:How to detect when a scene is loaded in A-Frame?如何检测场景何时加载到 A-Frame 中?
【发布时间】:2023-03-10 19:46:01
【问题描述】:

A-Frame 完全加载时是否会触发某些事件?现在我已经设法让我的document.querySelector(".a-enter-vr-button") 工作了,但只是在将它放在setTimeout 函数中之后,这似乎是一个临时的解决方案。因此,如果有人有任何方法在 A-Frame 完全加载后触发 js 脚本,请告诉我!

【问题讨论】:

    标签: aframe


    【解决方案1】:

    您可以使用loaded 事件:

    document.querySelector('a-scene').addEventListener('loaded', function () {...})

    但我们建议您使用组件,这样您就不必处理等待事件来进行设置:

    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);
      }
    });
    

    然后使用 HTML 中的组件:

    <a-scene log="Hello, Scene!">
      <a-box log="Hello, Box!"></a-box>
    </a-scene>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-01
      • 2017-12-29
      • 1970-01-01
      相关资源
      最近更新 更多