zoukankan      html  css  js  c++  java
  • 浏览器模拟touch

            var ele =  document.getElementById('trackLine')
            //may have x and y properties in some browsers,But it always has left, top, right, and bottom properties.
            var rect = ele.getBoundingClientRect(); 
            var touch = new Touch({
                "identifier" : 0,
                "target" : ele,
                "clientX" : (rect.left + rect.right)/2,
                "clientY" : (rect.top + rect.bottom)/2,
                "screenX" : (rect.left + rect.right)/2,
                "screenY" : (rect.top + rect.bottom)/2,
                "pageX" : (rect.left + rect.right)/2,
                "pageY" : (rect.top + rect.bottom)/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);
            
            window.interval = setInterval(function(){
                var touch = new Touch({
                "identifier" : 0,
                "target" : ele,
                "clientX" : (rect.left* Math.random() + rect.right * Math.random())/2,
                "clientY" : (rect.top* Math.random() + rect.bottom* Math.random())/2,
                "screenX" : (rect.left* Math.random() + rect.right* Math.random())/2,
                "screenY" : (rect.top* Math.random() + rect.bottom* Math.random())/2,
                "pageX" : (rect.left* Math.random() + rect.right* Math.random())/2,
                "pageY" : (rect.top* Math.random() + rect.bottom* Math.random())/2,
                "radiusX" : 11.5,
                "radiusY" : 11.5,
                "rotationAngle" : 0.0,
                "force" : 1});
                console.log(touch)
                var touchmove = new TouchEvent("touchmove", {
                    cancelable: true,
                    bubbles: true,
                    composed: true,
                    touches: [touch],
                    targetTouches: [touch],
                    changedTouches: [touch]
                });
                ele.dispatchEvent(touchmove);
            }, 20);
    
            
            
                
  • 相关阅读:
    2019年书单
    JMeter报错:Address already in use : connect
    读书笔记——弗洛伊德《梦的解析》
    Python3学习之路~10.3 论事件驱动与异步IO
    Python3学习之路~10.2 协程、Greenlet、Gevent
    nmon使用问题汇总(不定期更新)
    ( VIJOS )VOJ 1049 送给圣诞夜的礼品 矩阵快速幂
    POJ3233 Matrix Power Series 矩阵乘法
    NYOJ 298 点的变换 矩阵乘法
    HDU 5834 Magic boy Bi Luo with his excited tree 树形dp
  • 原文地址:https://www.cnblogs.com/rubekid/p/13922846.html
Copyright © 2011-2022 走看看