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);

你可能感兴趣的:(JS模拟Touch事件)