const RSWIPE = (function(){ function RSWIPE(){ this.step = 0.08 } /** * @description 仿真滑动 * @param startX {number} 起点x * @param startY {number} 起点y * @param endX {number} 终点x * @param endY {number} 终点y * @param timeStart {number} 随机延迟1,默认50ms * @param timeEnd {number} 随机延迟2,默认timeStart+50ms * @param timeOut {number} 超时,默认2s * @param step {number} 步进,默认0.08 * @return {boolean} */ RSWIPE.prototype.rndSwipe = function (startX, startY, endX, endY, timeStart, timeEnd, timeOut, step) { timeStart = timeStart || 50 timeEnd = timeEnd || timeStart + 50 timeOut = timeOut || 2 * 1000 this.step = step || this.step return this._gesture(this._rndSwipe(startX, startY, endX, endY), random(timeStart, timeEnd), timeOut) } /** * @description 二指仿真滑动 * @param startX {number} 起点x * @param startY {number} 起点y * @param endX {number} 终点x * @param endY {number} 终点y * @param timeStart {number} 随机延迟1,默认50ms * @param timeEnd {number} 随机延迟2,默认timeStart+50ms * @param timeOut {number} 超时,默认2s * @param step {number} 步进,默认0.08 * @return {boolean} */ RSWIPE.prototype.rndSwipeTwo = function (startX, startY, endX, endY, timeStart, timeEnd, timeOut, step) { timeStart = timeStart || 50 timeEnd = timeEnd || timeStart + 50 timeOut = timeOut || 2 * 1000 this.step = step || this.step return this._gestureTwo(this._rndSwipe(startX, startY, endX, endY), this._rndSwipe(startX, startY, endX, endY), random(timeStart, timeEnd), timeOut) } RSWIPE.prototype._bezier_curves = function (cp, t) { let cx = 3.0 * (cp[1].x - cp[0].x), bx = 3.0 * (cp[2].x - cp[1].x) - cx, ax = cp[3].x - cp[0].x - cx - bx, cy = 3.0 * (cp[1].y - cp[0].y), by = 3.0 * (cp[2].y - cp[1].y) - cy, ay = cp[3].y - cp[0].y - cy - by, tSquared = t * t, tCubed = tSquared * t return { "x": (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x, "y": (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y } } RSWIPE.prototype._rndSwipe = function (qx, qy, zx, zy) { let xxyy = [], xxy = [], point = [], dx = [{ "x": random(qx, qx + 50), "y": random(qy, qy + 50) }, { "x": random(qx - 100, qx + 100), "y": random(qy, qy + 50) }, { "x": random(zx - 100, zx + 100), "y": random(zy, zy + 50), }, { "x": zx, "y": zy }] for (let i = 0; i < dx.length; i++) { point.push(dx[i]) } for (let i = 0; i < 1; i += this.step) { xxyy = [~~(this._bezier_curves(point, i).x), ~~(this._bezier_curves(point, i).y)] xxy.push(xxyy); } return xxy } RSWIPE.prototype._gesture = function (swipeList, time, time1) { let touch1 = [{"action": 0, "x": swipeList[0][0], "y": swipeList[0][1], "pointer": 1, "delay": time}] for (let i = 1; i < swipeList.length - 1; i++) { touch1.push({"action": 2, "x": swipeList[i][0], "y": swipeList[i][1], "pointer": 1, "delay": time}); } touch1.push({ "action": 1, "x": swipeList[swipeList.length - 1][0], "y": swipeList[swipeList.length - 1][1], "pointer": 1, "delay": time }) return multiTouch(touch1, null, null, time1); } RSWIPE.prototype._gestureTwo = function (swipeList, time, time1) { let swipe = swipeList[0], swipe1 = swipeList[1], touch1 = [{"action": 0, "x": swipe[0][0], "y": swipe[0][1], "pointer": 1, "delay": time}], touch2 = [{"action": 0, "x": swipe1[0][0], "y": swipe1[0][1], "pointer": 2, "delay": time}] for (let i = 1; i < swipe.length - 1; i++) { touch1.push({"action": 2, "x": swipe[i][0], "y": swipe[i][1], "pointer": 1, "delay": time}); touch2.push({"action": 2, "x": swipe1[i][0], "y": swipe1[i][1], "pointer": 2, "delay": time}); } touch1.push({ "action": 1, "x": swipe[swipe.length - 1][0], "y": swipe[swipe.length - 1][1], "pointer": 1, "delay": time }) touch2.push({ "action": 1, "x": swipe1[swipe1.length - 1][0], "y": swipe1[swipe1.length - 1][1], "pointer": 2, "delay": time }) return multiTouch(touch1, touch2, null, time1); } return RSWIPE; })();