【问题标题】:Aframe device detectionAframe 设备检测
【发布时间】:2018-05-23 12:08:01
【问题描述】:

我尝试在浏览器中禁用我的光标有什么想法吗?在 aframesite (https://aframe.io/docs/master/core/utils.html#function-utils) 上,我找到了 AFRAME.utils.device.isMobile () 但我不知道我应该如何处理它我尝试了这样的事情:

<script>AFRAME.utils.device.isMobile ()
  if (isMobile = true){
    console.log('hallo mobile');
  } else {
    console.log('hallo browser');
  }
</script>

所以我可以看看我是否至少可以检测到它,但我想我有语法问题,请帮助 :) 如果需要,这里是我的光标组件。

<!--camera-->
<a-entity rotation="0 90 0">
  <a-camera user-height="0" look-controls>
    <a-cursor cursor="fuse: true; fuseTimeout: 2000"
        position="0 0 -0.1"
        geometry="primitive: ring;
        radiusInner: 0.002;
        radiusOuter: 0.003"
        material="color: red; shader: flat">
        <a-animation attribute="scale"
                          to="3 3 3"
                          dur="2000"
                          begin="cursor-fusing"
                          fill="backwards"
                          easing="linear">
             </a-animation>
    </a-cursor>
    <a-entity position="0 0 -0.1" 
        geometry="primitive: ring;
        radiusInner: 0.009;
        radiusOuter: 0.0095"
        material="color: red; opacity: 0.25; shader: flat"></a-entity>
  </a-camera>  
</a-entity>  

【问题讨论】:

    标签: jquery browser device detection aframe


    【解决方案1】:

    用一个简单的组件来切换光标的可见性怎么样:

    AFRAME.registerComponent("foo", {
      init: function() {
       var cursor = document.querySelector("a-cursor")
       if (AFRAME.utils.device.isMobile() === false) {
          cursor.setAttribute("visible", false);
          //or just cursor.parentNode.removeChild(cursor)
          this.el.sceneEl.setAttribute("cursor","rayOrigin","mouse")
       }
     }
    })
    

    使用这样的设置:

    <!--camera-->
    <a-entity foo rotation="0 90 0">
      <a-camera user-height="0" look-controls>
        <a-cursor fuse="true" fuseTimeout="2000"
          position="0 0 -0.1"
          geometry="primitive: ring;
          radiusInner: 0.002;
          radiusOuter: 0.003"
          material="color: red; shader: flat">
          <a-animation attribute="scale"
                          to="3 3 3"
                          dur="2000"
                          begin="cursor-fusing"
                          fill="backwards"
                          easing="linear">
          </a-animation>
       </a-cursor>
     </a-camera>  
    </a-entity>  
    

    【讨论】:

    • 不会工作 :) 但如果它有效并且我的光标被禁用,他是否仍然会激活东西?
    • 现在检查一下,如果是移动设备,没有任何变化,如果 PC 没有响铃,但鼠标光标
    • 感谢很多光标在浏览器中是不可见的,但在移动设备上仍然存在。现在我只需要弄清楚如何在浏览器上禁用他的功能,这样就不会有人误触发事件
    • 您也可以使用cursor.parentNode.removeChild(cursor) 删除&lt;a-cursor&gt; :)
    • 太棒了:D谢谢它的工作原理。现在我只需要在您在浏览器中按下 vr-mode 时将其取回
    猜你喜欢
    • 2021-04-08
    • 1970-01-01
    • 2017-04-13
    • 2012-05-10
    • 2013-04-27
    • 1970-01-01
    • 2023-03-09
    • 2014-07-05
    • 1970-01-01
    相关资源
    最近更新 更多