zoukankan      html  css  js  c++  java
  • mobile touch 备用

     1 var _scrollIndex=1;
     2 function scrollPage(){
     3     var _contentEle = $('.view-container'),_viewEle = _contentEle.find('.view');
     4     var _iconEle = $('.downIconArror');
     5     var _view_port = $('.view-port');
     6     var _touchEvents = {
     7         'pageYStart':'',
     8         'pageYEnd':'',
     9         'touchstart':function(event){
    10             event.preventDefault();
    11             var _touch = event.touches[0],_this = _touchEvents;
    12             _this.pageYStart = _touch.pageY;
    13             _view_port[0].addEventListener('touchmove',_this.touchmove,true);
    14             _view_port[0].addEventListener('touchend',_this.touchend,true);
    15         },
    16         'touchmove':function(event){
    17             event.preventDefault();
    18             var _touch = event.touches[0],_this = _touchEvents;
    19             _this.pageYEnd = _touch.pageY;
    20         },
    21         'touchend':function(event){
    22             var _this = _touchEvents;
    23             var _distance = _this.pageYEnd-_this.pageYStart;
    24             if(_distance>50){
    25                 swipe.down();
    26             }
    27             if(_distance<-50){
    28                 swipe.up();
    29             }
    30             _view_port[0].removeEventListener('touchmove',_this.touchmove);
    31             _view_port[0].removeEventListener('touchend',_this.touchend);
    32         }
    33     };
    34     _view_port[0].addEventListener('touchstart',_touchEvents.touchstart);
    35     var swipe = {
    36         up:function(){
    37             var _this = _contentEle;
    38             var _initTransY = getTransform(_this);
    39             if(Math.abs(_initTransY)==(_viewEle.length-1)*_viewEle.height()){
    40                 return;
    41             }
    42             if(Math.abs(_initTransY)==(_viewEle.length-2)*_viewEle.height()){
    43                 _iconEle.hide();
    44             }else{
    45                 _iconEle.show();
    46             }
    47             _scrollIndex++;
    48             scrollPageAnimate(_scrollIndex);
    49             _this.animate({'margin-top':parseInt(_initTransY-_viewEle.height())},500);
    50         },
    51         down:function(){
    52             var _this = _contentEle;
    53             var _initTransY = getTransform(_this);
    54             _iconEle.show();
    55             if(_initTransY==0){
    56                 return;
    57             }
    58             _scrollIndex--;
    59             scrollPageAnimate(_scrollIndex);
    60             _this.animate({'margin-top':parseInt(_initTransY+_viewEle.height())},500);
    61         }
    62     }
    63 }
  • 相关阅读:
    面试题12:打印1到最大的n位数
    java生成指定范围的随机数
    排序
    Java中的String类和算法例子替换空格
    动态规划、贪心算法笔记
    牛客编程巅峰赛S1第2场
    UVA 489
    UVA 1339
    UVA 1587
    UVA 202
  • 原文地址:https://www.cnblogs.com/zfdai/p/4463609.html
Copyright © 2011-2022 走看看