2016-10-22 70 views
0

我正在使用带嵌入属性的A帧。通过A-Frame的VR模式按钮隐藏页面元素

请参阅本codepen:

http://codepen.io/ymcheung/full/zKyyqX/

<a-scene embedded> 
    <a-sky src="https://raw.githubusercontent.com/aframevr/aframe/master/examples/boilerplate/panorama/puydesancy.jpg" rotation="0 -130 0"></a-sky> 
</a-scene> 

// .a-enter-vr-button is supplied by A-Frame 
var sceneVRButton = document.querySelector('.a-enter-vr-button'); 

点击在右下角的VR模式按钮将同时进入VR-玻璃桌面上进入全屏模式移动模式。

在移动模式下,工具栏仍然在屏幕上,我想暂时隐藏它。

function hideinHome() 
{ 
    document.querySelector('.floatingBar').style.opacity = 0; 
} 

sceneVRButton.addEventListener('click', hideinHome, false); 

但是,似乎A-Frame的DOM后装比javascript。

在Chrome的控制台有消息:

Uncaught TypeError: Cannot read property 'addEventListener' of null 

在那里“听”到A型架的海外省或移动进入全屏模式的任何方式?

谢谢!

回答

1

编写一个A-Frame组件,以便您不必手动等待初始化。

AFRAME.registerComponent('hide-on-enter-vr-click', { 
    schema: {type: 'selector'}, 

    init: function() { 
    var element = this.data; 
    var button = this.el.querySelector('.a-enter-vr-button'); 
    button.addEventListener('click', function() { 
     element.style.opacity = 0; 
    }); 
    } 
}); 

然后在把它捞起来。

<a-scene hide-on-enter-vr-click=".floatingBar"></a-scene> 
+0

谢谢!!它非常简单直观。 – ymcheung