用a-frame设置加载动画

0 aframe

我正在使用 a-frame 加载带有以下示例代码的全景照片。它在加载照片时显示白屏,并持续几秒钟,这会造成糟糕的用户体验。我想在加载照片时添加加载动画,但找不到任何有用的指南。有人可以帮忙吗?

<a-scene>
  <a-assets>
    <img id="sky" src="sky.png">
  </a-assets>
  <a-sky src="#sky"></a-sky>
</a-scene>
Run Code Online (Sandbox Code Playgroud)

小智 5

我认为 aframe 8 将有一个内置的加载屏幕。与此同时,这是我目前如何处理从 Ottifox 导出的 aframe 场景的方法:

首先在a-scene标签之前和正文开始之后,我有这个标记:

<div id="splash">
  <div class="loading"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

然后在一个css文件中:

#splash {
  position: absolute;

  display: flex;
  align-items: center;
  justify-content: center;

  top: 0;
  bottom: 0;
  left: 0;
  right: 0;

  width: 200px;
  height: 200px;

  margin: auto;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.loading {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 0.25rem solid rgba(255, 255, 255, 0.2);
  border-top-color: white;
  animation: spin 1s infinite linear;
}
Run Code Online (Sandbox Code Playgroud)

最后在 main.js

document.addEventListener('DOMContentLoaded', function() {
    var scene = document.querySelector('a-scene');
    var splash = document.querySelector('#splash');
    scene.addEventListener('loaded', function (e) {
        splash.style.display = 'none';
    });
});
Run Code Online (Sandbox Code Playgroud)

您可以在此处查看示例的源代码,一起查看:http : //ottifox.com/examples/space/index.html