$.fn.tap =function(FN) {varCollection = This, Istouch= "Ontouchend"inchDocument.createelement ("div"), Tstart= Istouch? "Touchstart": "MouseDown", Tmove= Istouch? "Touchmove": "MouseMove", tend= Istouch? "Touchend": "MouseUp", Tcancel= Istouch? "Touchcancel": "Mouseout"; Collection.each (function(){ vari = {}; I.target= This; $ (I.target). On (Tstart,function(e) {varp = "Touches"inchE? E.touches[0]: (Istouch? window.event.touches[0]: window.event); I.startx=P.clientx; I.starty=P.clienty; I.endx=P.clientx; I.endy=P.clienty; I.starttime= +NewDate; }); $ (I.target). On (Tmove,function(e) {varp = "Touches"inchE? E.touches[0]: (Istouch? window.event.touches[0]: window.event); I.endx=P.clientx; I.endy=P.clienty; }); $ (I.target). On (Tend,function(e) {if((+NewDate)-i.starttime<300){ if(Math.Abs (I.ENDX-I.STARTX) +math.abs (i.endy-i.starty) <20){ varE = e | |window.event; E.preventdefault (); Fn.call (I.target); }} i.starttime=undefined; I.startx=undefined; I.starty=undefined; I.endx=undefined; I.endy=undefined; }); }); returncollection;}
JQuery Tap Plugin