Compatible with a plug-in phone and PC, just simple up, down, left, right. have uploaded my files inside.
Http://files.cnblogs.com/files/yjhua/touchwipe.js
The source code is as follows:
/**----------------------* touchwipe *----------------------* http://www.uedcool.com * by Eddyzhang (Zhang Yonghui) * Version 2.0 * 2011/12/29 * * #example: * $ ("#test"). Touchwipe ({* min_move_x:40,//transverse sensitivity * min_move_y:40,//longitudinal sensitivity * wipeleft:function () {$ ("#val"). Append ("left,");},//left swipe event * WI Peright:function () {$ ("#val"). Append ("right,");},//Right Swipe event * Wipeup:function () {$ ("#val"). Append ("Top,");},//Slide up Event * Wipedown:function () {$ ("#val"). Append ("Down,");},//Swipe down event * Wipe:function () {$ ("#val"). Append (" Click, ");},//Touch event * Wipehold:function () {$ (" #val "). Append (" Hold, ");},//Touch Hold Event * PREVENTDEFAULTEVENTS:TR UE//block default event *}); * */(function(a) {A.fn.touchwipe=function(c) {varb={cleartouchwipe:false, drag:false, min_move_x:20, min_move_y:20, Wipeleft:function(){/*Swipe left*/}, Wiperight:function(){/*Swipe Right*/}, Wipeup:function(){/*swipe up*/}, Wipedown:function(){/*Swipe down*/}, Wipe:function(){/*Click*/}, Wipehold:function(){/*Touch Hold*/}, Wipedrag:function(x, Y) {/*Drag*/}, Preventdefaultevents:false }; if(c) {a.extend (b,c)}; This. each (function(){ varh,g,j=false, i=false, E; varSupporttouch = "Ontouchstart"inchdocument.documentelement; varMoveevent = Supporttouch? "Touchmove": "MouseMove", Startevent= Supporttouch? "Touchstart": "MouseDown", EndEvent= Supporttouch? "Touchend": "MouseUp"/*Remove Touchmove Monitor*/ functionm () { This. RemoveEventListener (MOVEEVENT,D); H=NULL; J=false; Cleartimeout (e)}; /*Event Handling Methods*/ functiond (q) {if(b.preventdefaultevents) {q.preventdefault ()}; if(j) {varn = supporttouch? Q.touches[0].pagex:q.pagex; varr = Supporttouch? Q.touches[0].pagey:q.pagey; varp = hN; varo = G0; if(B.drag) {h=N; G=R; Cleartimeout (e); B.wipedrag (P,o); } Else{ if(Math.Abs (P) >=b.min_move_x) {m (); if(p>0) {b.wipeleft ()}Else{b.wiperight ()}}Else{ if(Math.Abs (o) >=b.min_move_y) {m (); if(o>0) {b.wipeup ()}Else{B.wipedown ()}}} } } }; /*Wipe Treatment Method*/ functionK () {cleartimeout (e);if(!I&&J) {b.wipe ()};i=false; j=false;}; /*Wipehold Treatment Method*/ functionL () {i=true; B.wipehold ()}; functionf (n) {//if (n.touches.length==1) {h = Supporttouch? N.touches[0].pagex:n.pagex; G= Supporttouch? N.touches[0].pagey:n.pagey; J=true; This. AddEventListener (Moveevent,d,false); E=settimeout (l,750) //} }; //if ("Ontouchstart" in document.documentelement) { if(b.cleartouchwipe) { This. RemoveEventListener (Startevent,f,false); This. RemoveEventListener (Endevent,k,false); }Else{ This. AddEventListener (Startevent,f,false); This. AddEventListener (Endevent,k,false) } //} }); return This };}) (jQuery);
View Code
Compatible with a plugin for mobile phone and PC Touchwipe