html5 touch事件实现触屏页面上下滑动(二)

2020-04-21 22:40:18易采站长站整理

  
            function touchMove(e){//滑动   
                 e.preventDefault();   
                var  touch = e.touches[0];                  
                 y = touch.pageY – startY;//滑动的距离                                             
                 inner.style.top=aboveY+y+"px";       
                 document.getElementById("spText").innerHTML=inner.style.top;      
                            
                                  
            }     
  
            function touchEnd(e){//手指离开屏幕                            
                 aboveY=parseInt(inner.style.top);//touch结束后记录内部滑块滑动的位置 在全局变量中体现 一定要用parseInt()将其转化为整数字;   
                  if(y>0&>0){//当滑动到最顶端时候不能再网上滑动   
                      //inner.style.top=0;   
                       $("#inner").animate({top:0},200);   
                       aboveY=0;