JavaScript code:
$.swipe=function(opt) {
varo = $.extend ({
Mainselector: "",
Swipeleft:function(E,V) {},
Swiperight:function(E,V) {},
Swipeends:function(v,e) {}
}, opt | | {});
varstartx=0,starty=0;
varobj={
Touchstart:function(e) {
varTouchx= E.touches[0].pagex;
varTouchy= E.touches[0].pagey;
StartX = parseint (touchx,10);
Starty = parseint (touchy,10);
},
TouchMove:function(e) {
varTouchmx= E.touches[0].pagex,
Touchmy= E.touches[0].pagey,
Dirx=parseint (touchmx-startx,10);
Diry=parseint (touchmy-starty,10);
if(dirx<0) {
O.swipeleft (E,dirx);
}Else{
O.swiperight (E,dirx);
}
if(diry<0) {
O.swipetop (E,diry);
}Else{
O.swipebottom (E,diry);
}
},
Touchend:function(e) {
O.swipeends (e);
},
Bindevent:function(ELS) {
varelem=$ (ELS);
for(vari=0,_len=elem.length;i<_len;i++) {
Elem[i].addeventlistener (' Touchstart ', Obj.touchstart,false);
Elem[i].addeventlistener (' Touchmove ', Obj.touchmove,false);
Elem[i].addeventlistener (' Touchend ', Obj.touchend,false);
}
}
};
Obj.bindevent (O.mainselector);
returnObj};
Thecallback event that is passed in is the selector and swipeleft,swiperight