gpt4 book ai didi

javascript - 是否可以在框架中获取触摸事件(在移动浏览器上)?

转载 作者:行者123 更新时间:2023-12-03 06:00:51 24 4
gpt4 key购买 nike

我尝试向我的 aframe 实体添加 onclick 事件,如下所示:

<a-sphere id="sphere1" onclick="moveSphere()"
position="0 1.25 -1" radius="1.25" color="#EF2D5E"></a-sphere>

但它不适用于移动设备。

或者,我尝试像这样添加触摸事件监听器,但没有任何反应:

sphereElement.addEventListener('touchend', moveSphere);

最佳答案

3D 元素与 DOM 元素不同,你不能像 touchend 那样在它们上注册普通的 DOM 事件。您必须在canvas

上注册它们

要实现这一点,您需要一个像 https://jesstelford.github.io/aframe-click-drag-component/ 这样的光线转换器解决方案。

<head>
<script src="https://aframe.io/releases/0.3.0/aframe.min.js"></script>
<script src="https://unpkg.com/aframe-click-drag-component"></script>
<script>
registerAframeClickDragComponent(window.AFRAME);
</script>
</head>

<body>
<a-scene>
<a-sphere click-drag position="0 1.25 -5" radius="1.25" color="#EF2D5E"></a-sphere>
<a-camera look-controls-enabled="false"></a-camera>
</a-scene>
</body>

关于javascript - 是否可以在框架中获取触摸事件(在移动浏览器上)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39754579/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com