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);
    
            
            
                
  • 相关阅读:
    防止域名恶意指向的解决办法
    Spring @Configuration @Import
    CAS 集成认证
    远程桌面登录蓝色屏幕、不显示桌面怎么解决?
    终端服务器超出了最大允许连接数
    Fiddler 常见几种解决捕获不到请求的方法
    android TimerTask 的简单应用
    Android 数字签名学习笔记
    Android 遍历卡数据并按图片,音乐等分类保存
    Android 最简单的SD卡文件遍历程序
  • 原文地址:https://www.cnblogs.com/rubekid/p/13922846.html
Copyright © 2011-2022 走看看