鼠标事件在移动设备中不起作用 [英] Mouse events not working in mobile

查看:97
本文介绍了鼠标事件在移动设备中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了这个 360 全景图像,它在桌面上运行良好,但在手机上鼠标事件不工作.我如何为移动设备解决这个问题?

I created this 360 panorama image which is working fine in desktop but on mobile phones the mouse events are not working. How can i fix this for mobile?

//监听器

document.addEventListener("mousedown", onDocumentMouseDown, false);
document.addEventListener("mousemove", onDocumentMouseMove, false);
document.addEventListener("mouseup", onDocumentMouseUp, false);

我将事件更改为

document.addEventListener("touchstart", onDocumentMouseDown, false);
document.addEventListener("touchmove", onDocumentMouseMove, false);
document.addEventListener("touchend", onDocumentMouseUp, false);

但这不适用于移动设备.

but this is not working for mobile.

推荐答案

我找到了答案.对于触摸 event.clientX 和 event.clientY 不起作用,我已将其更改为 event.touches[0].clientX 和 event.touches[0].clientY,它修复了触摸事件问题.

i found the answer. For touch event.clientX and event.clientY were not working which i have changed to event.touches[0].clientX and event.touches[0].clientY and it fixed the touch event issue.

这篇关于鼠标事件在移动设备中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆