2016-10-22 109 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