Recently idle to Nothing, wrote a mobile side of the event library, code affixed below, we do not shoot.
1 /**2 @version 1.0.03 @author Gangli4 @deprecated Mobile-touch Event Library5 */6(function () {7"Use Strict";8 varUtil = {9$:function(selector) {Ten returnDocument.queryselector (selector); One }, AGeteventinfo:function(e) { - var_e = {}; -_e.pagex = E.changedtouches[0].pagex; the_e.pagey = E.changedtouches[0].pagey; -_e.target =E.target; - return_e; - } + }; - var_tap =function(callback) { + This. AddEventListener (' Touchstart ',function(e) { A var_e =Util.geteventinfo (e); at_e.type = ' tap '; -Callback.call ( This, _e); -},false); - }; - var_longtap =function(callback) { - varInterval = 800, S, E, Timer, El; in This. AddEventListener (' Touchstart ',function(e) { - var_e =Util.geteventinfo (e); toEl =_e.target; +s =Date.now (); -Timer = SetTimeout (function () { the_e.type = ' Longtap '; * Callback.call (el, _e); $ }, interval);Panax Notoginseng},false); - This. AddEventListener (' Touchend ',function(e) { the cleartimeout (timer); +},false); A }; the var_swipe =function(callback) { + vars = {}, E = {}, d = {}, distance = 50, -Angle = 0, $ type; $ This. AddEventListener (' Touchstart ',function(evt) { - var_e =Util.geteventinfo (evt); -S.x =_e.pagex; theS.y =_e.pagey; - Evt.preventdefault ();Wuyi},false); the This. AddEventListener (' Touchend ',function(evt) { - var_e =Util.geteventinfo (evt); Wue.x =_e.pagex; -E.y =_e.pagey; AboutD.x = e.x-s.x; $D.y = e.y-S.y; - if(Math.Abs (d.x) < distance && Math.Abs (D.Y) < distance)return false; -Angle = Math.Abs (Math.atan (E.Y-S.Y)/(e.x-s.x)/Math.PI * 180); - if(Angle > 45) { AType = D.y < 0? ' swipe-up ': ' Swipe-down '; +}Else { theType = d.x < 0? ' Swipe-left ': ' Swipe-right '; - } $Callback.call ( This, { the Type:type, the Start:s, the End:e, the Distance:d, - Target: _e.target in }); the Evt.preventdefault (); the},false); About } the var_drag =function(callback) { the varDragStart =false, S = {}, E = {}, o = {}; the This. AddEventListener (' Touchstart ',function(evt) { +DragStart =true; - var_e =Util.geteventinfo (evt); theS.x =_e.pagex;BayiS.y =_e.pagey; the Evt.preventdefault (); the},false); - This. AddEventListener (' Touchmove ',function(evt) { - if(!dragstart)return; the var_e =Util.geteventinfo (evt); theo.x = _e.pagex-s.x; theO.Y = _e.pagey-S.y; theCallback.call ( This, { -Type: "Drag-move", the Start:s, the Offset:o, the Target: _e.target94 }); the},false); the This. AddEventListener (' Touchend ',function(evt) { theDragStart =false;98 var_e =Util.geteventinfo (evt); Aboute.x =_e.pagex; -E.y =_e.pagey;101Callback.call ( This, {102Type: "Drag-end",103 Start:s,104 Offset:o, the End:e,106 Target: _e.target107 });108},false);109 } the varEventMap = {111 tap: _tap, the Swipe: _swipe,113 Longtap: _longtap, the Drag: _drag the } the varKtouch = {117Ver: ' 1.0.0 ',118Onfunction(EL, type, fn) {119 Try { - varEl =util.$ (EL);121 eventmap[type].call (el, FN);122 return This;123}Catch(e) {124Console.error (' type error:%s is not allowed ', type); the }126 }127 } -Window.ktouch =Ktouch;129})();
GitHub site: Https://github.com/kbqncf/ktouch