HTML5 拖拽事件移动端兼容问题?

现在拖动一个按钮,按下鼠标拖动,把鼠标移动出浏览器或者移到标签地址栏的时候再up,希望触发停止拖拽。在pc上都是可以的,移动端就有问题了。请问有什么兼容的方式吗?代码如下

document.onmousedown = function (e) {
    document.onmousemove = function () {
        console.log('move');
    };
    document.onmouseup = function () {
        console.log('mousestop');
        document.onmousemove = null;
        document.onmouseup = null;
    };
};
阅读 6.9k
1 个回答

移动端不是mousedownmousemovemouseup
相应的应是touchstarttouchmovetouchend

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题