打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
JS模拟Touch事件

当前在浏览器console模式下无法采用和click一样的方式touch某个节点,当前最新触发touch事件的方式如下:

        var ele = $('Test');
        var rect = ele.getBoundingClientRect();
        var touch = new Touch({
            "identifier" : 0,
            "target" : ele,
            "clientX" : rect.x + rect.width/2,
            "clientY" : rect.y + rect.height/2,
            "screenX" : rect.x + rect.width/2,
            "screenY" : rect.x + rect.width/2,
            "pageX" : rect.x + rect.width/2,
            "pageY" : rect.x + rect.width/2,
            "radiusX" : 11.5,
            "radiusY" : 11.5,
            "rotationAngle" : 0.0,
            "force" : 1});
        
        var touchstart = new TouchEvent("touchstart", {
            cancelable: true,
            bubbles: true,
            composed: true,
            touches: [touch],
            targetTouches: [touch],
            changedTouches: [touch]
        });
        
        var touchend = new TouchEvent("touchend", {
            cancelable: true,
            bubbles: true,
            composed: true,
            touches: [touch],
            targetTouches: [touch],
            changedTouches: [touch]
        });
        
        ele.dispatchEvent(touchstart);
        ele.dispatchEvent(touchend);
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
JS移动客户端
移动端事件(touchstart+touchmove+touchend)
移动端 滑动touchstart touchmove touchend
html5 touch事件实现触屏页面上下滑动(一)
移动端事件介绍
指尖下的js ——多触式web前端开发之一:对于Touch的处理
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服