栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

用于触摸设备的Javascript拖放

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

用于触摸设备的Javascript拖放

您可以使用JqueryUI进行拖放,并使用一个额外的库来将鼠标事件转换为您需要的触摸,我建议使用的库为/furf/jquery-ui-touch-punch,这从Jquery UI拖放到触摸装置

或者您可以使用我正在使用的这段代码,它也可以将鼠标事件转换为触摸事件,并且就像魔术一样工作。

function touchHandler(event) {    var touch = event.changedTouches[0];    var simulatedEvent = document.createEvent("MouseEvent");        simulatedEvent.initMouseEvent({        touchstart: "mousedown",        touchmove: "mousemove",        touchend: "mouseup"    }[event.type], true, true, window, 1,        touch.screenX, touch.screenY,        touch.clientX, touch.clientY, false,        false, false, false, 0, null);    touch.target.dispatchEvent(simulatedEvent);    event.preventDefault();}function init() {    document.addEventListener("touchstart", touchHandler, true);    document.addEventListener("touchmove", touchHandler, true);    document.addEventListener("touchend", touchHandler, true);    document.addEventListener("touchcancel", touchHandler, true);}

在您的document.ready中,只需调用init()函数



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/464605.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号