首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过凝视按钮在Aframe中输入VR。

通过凝视按钮在Aframe中输入VR。
EN

Stack Overflow用户
提问于 2018-09-05 15:27:52
回答 1查看 172关注 0票数 0

我启用了虚拟现实模式-ui,我想有一个按钮在我的aframe场景,进入虚拟现实模式点击。我的问题是我的js给了我一个TypeError: document.getElementById(.)是空的,我不知道为什么!

代码语言:javascript
复制
<script>
AFRAME.registerComponent('enter', {
  init: function () {
  }
}); 

document.getElementById('startbutton').addEventListener("click", (e)=>{
    scene.enterVR(true);
});
</script>

<a-scene id="scene" antialias="true"; cursor="rayOrigin: mouse" vr-mode-ui="enabled: true">

<a-assets>
<img id="startscreen" src="start_overlay.png">  
</a-assets>

<!-- Environment -->

<a-sky id="environment" radius="9" rotation="0 -90 0"; material="shader: flat; src: #xxx"></a-sky>

<!-- Camera + cursor + Startscreen + Interaction-->
<a-entity look-controls>
    <a-entity id="start">
            <a-plane id="startbutton" class="link"; height="0.5"; width="5"; position="0 -0.7 -2" rotation="0 0 0" color="#ffbff0">

            <a-text align="center" value="START" width="10" color="#e143a1"></a-text>
            </a-plane>

    </a-entity>

    <a-entity id="cam" camera rotation="0 0 0" mouse-cursor>                
        <a-cursor id="cursor" color="red"
          animation__click="property: scale; startEvents: click; from: 0.1 0.1 0.1; to: 1 1 1; dur: 150"
          animation__fusing="property: fusing; startEvents: fusing; from: 1 1 1; to: 0.1 0.1 0.1; dur: 1500"
          event-set__1="_event: mouseenter; color: white"
          event-set__2="_event: mouseleave; color: red"
          fuse="true"
          raycaster="objects: .link"></a-cursor>
    </a-entity>

</a-entity>

</a-scene>

我不认识t know why my button isn的js-脚本!

有人能帮忙吗拜托!干杯,能

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-05 15:42:37

在执行代码时,该按钮可能不在DOM中。要么是:

1)将代码放入AFRAME组件中,

2)将代码放在HTML主体之后,或

3)将其放入window.onload回调中:

代码语言:javascript
复制
window.onload = function() {
  doSomething();
};

另外,正如您在文档中所看到的,正确的方法是在场景元素上调用enterVR()exitVR()。确保您使用的scene引用实际保存了场景元素。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52188771

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档