//左右滑动切换 var nStartY; var nStartX; var nChangY; var nChangX; document.getElementsByTagName('body')[0].addEventListener('touchstart',function(e){ nStartY = e.targetTouches[0].pageY; nStartX = e.targetTouches[0].pageX; }); document.getElementsByTagName('body')[0].addEventListener('touchmove',function(e){ e.preventDefault(); }); document.getElementsByTagName('body')[0].addEventListener('touchend',function(e){ nChangY = e.changedTouches[0].pageY; nChangX = e.changedTouches[0].pageX; var distance = nChangX - nStartX; var distance1 = nChangY - nStartY; if(distance > 50){//左滑 alert('左滑'); }else if(distance < -50){ alert('右滑'); } });