determine if the phone:
function IsMobile () {var suseragent= navigator.userAgent.toLowerCase (), bisipad= suseragent.match (/ipad/i) = = "ipad", bisiphoneos= Suseragent.match (/iphone os/i) = = "iphone os", bismidp= suseragent.match (/midp/i) = = "MIDP", bisuc7= SU Seragent.match (/rv:1.2.3.4/i) = = "rv:1.2.3.4", bisuc= suseragent.match (/ucweb/i) = = "UCWeb", bisandroid= sUserAgent.ma TCH (/android/i) = = "Android", Bisce= Suseragent.match (/windows ce/i) = = "Windows CE", biswm= suseragent.match (/windows mobile/i) = = "Windows Mobile", Biswebview = Suseragent.match (/webview/i) = = "WebView"; Return (Bisipad | | bisiphoneos | | bismidp | | bIsUc7 | | bisuc | | bisandroid | | bisce | | biswm); }
To judge the use of that event:var touchstart,touchmove,touchend; Touchstart = IsMobile ()? ' Touchstart ': ' MouseDown '; TouchMove = IsMobile ()? ' Touchmove ': ' MouseMove '; Touchend = IsMobile ()? ' Touchend ': ' MouseUp ';
the corresponding handling of three kinds of events:Touchstart:function (e) {var e=e | | window.event;//To determine which event to useStopdefault (e);//Different browser, block browser default event method is differentif (IsMobile ()) {//If it is a mobile phonevar touch=e.touches[0]; This.y1=touch.pagey}else{This.y1=e.pagey;//If not mobile} this.y2=0; }, Touchmove:function (e) {var e=e | | window.event; Stopdefault (e); if (IsMobile ()) {var touch=e.touches[0]; This.y2=touch.pagey; }else{This.y2=e.pagey; } },
Touchend:function (e) {var e=e | | window.event; Stopdefault (e); if (this.y2==0) {return; } var Diffy=this.y2-this.y1; if (diffy>50) {this.donext (); }else if (diffy<-50) {This.doprev (); } this.y1=0, this.y2=0; },
Block Browser Default event methods:function Stopdefault (e) {var e=e | | window.event; if (E.preventdefault) {e.preventdefault (); }else{E.returnvalue=false; } }
Judging the difference between the phone and the PC, the events are different.