码迷,mamicode.com
首页 > Web开发 > 详细

js_fake_touch

时间:2020-02-23 09:43:48      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:com   pat   ORC   let   ott   dispatch   cancel   compose   document   

        let ele =  document.getElementById('GameCanvas');
        let rect = ele.getBoundingClientRect();
        let 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});

        let touchstart = new TouchEvent("touchstart", {
            cancelable: true,
            bubbles: true,
            composed: true,
            touches: [touch],
            targetTouches: [touch],
            changedTouches: [touch]
        });

        let touchend = new TouchEvent("touchend", {
            cancelable: true,
            bubbles: true,
            composed: true,
            touches: [touch],
            targetTouches: [touch],
            changedTouches: [touch]
        });

        ele.dispatchEvent(touchstart);
        ele.dispatchEvent(touchend);

js_fake_touch

标签:com   pat   ORC   let   ott   dispatch   cancel   compose   document   

原文地址:https://www.cnblogs.com/daihanlong/p/12348362.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!