【发布时间】:2018-07-26 13:03:35
【问题描述】:
我想通过触摸在移动设备中移动图像,例如当用户将手指移到页面上时,图像会继续移动并始终停留在用户手指位置,例如网络光标,我正在使用此代码:
document.addEventListener('touchmove', this.onMouseMove);
document.addEventListener('touchStart', this.onMouseMove);
document.addEventListener('touchEnd', this.onMouseMove);
和
onMouseMove = (e) => {
const img = document.getElementById('drawing-mouse-pointer');
img.style.left = `${e.touches[0].clientX}px`;
img.style.top = `${e.touches[0].clientY }px`;
console.log(e.touches[0] && e.touches[0].clientY);
}
但图像仅在用户单击然后停止时移动一次。我怎样才能通过触摸继续移动图像。
【问题讨论】:
-
我觉得你只需要绑定到touchmove,试试去掉start和end的监听器
标签: javascript android css touch-event