首页 > 解决方案 > android上的Chrome:touchevent不适用于实体点击

问题描述

问题的问题是:从 VR 模式通过触摸点击移动设备的点击事件不适用于 Android Chrome 79+。换句话说,在 VR 模式下的实体上不会触发 touchstart 事件。已安装并启用 Google VR 服务。

目标 a-entity 应该可以在 Chrome 最新 79+ 中点击用户点击(VR 模式触摸点击来自移动设备)

整个代码的链接:这里 2 配置简单的应用程序: https ://4dkly.csb.app/(配置:fuse 3.6sec;但单击实体在 chrome vr 中不起作用) https://codesandbox.io/s/aframe -example-4dkly?fontsize=14&hidenavigation=1&theme=white

https://12k87.csb.app/(光标颜色为红色;保险丝已关闭,光标仍然不起作用)
https://codesandbox.io/s/aframe-example-12k87?fontsize=14&hidenavigation=1&theme=dark 你能请查看此示例中的任何一个,并告诉您要做什么,以使 chrome 最新,vr 模式触摸单击。任何新的好方法新的api也可以。

这里代码摘录

 <script src="https://aframe.io/releases/1.0.1/aframe.min.js"></script>

    <a-scene main> 
      <a-sphere position="0 2 -5" radius="1.25" color="#EF2D5E"> </a-sphere>
 <!-- ... -->

      <a-camera id="camera" camera rotation>
        <a-entity
          id="cursor"
          cursor="fuse:false"
          position="0 0 -1"
          material="color: #111;"

        >
        </a-entity>
      </a-camera>
//simple event on click 
 document.querySelector("a-box").addEventListener("click", () => {
   alert("box");
});```  

标签: google-chromeaframetouch-eventontouch

解决方案


您描述的行为是预期的。当通过 WebXR 进入沉浸式模式时,浏览器会禁用触摸事件,因为 Chrome 79+ 和提供的内容就是这种情况https。有新的 API 正在开发中,以在 AR 中呈现时启用交互性。您可以在此博客文章中找到更多详细信息:https ://aframe.io/blog/webxr-ar-module/

在没有原生 WebXR 实现的设备上,VR 模式依赖于全屏 API,并且可以使用触摸事件。

我不建议在 VR 中依赖屏幕输入并使用基于保险丝的光标


推荐阅读