js 下拉刷新页面

使用场景

当网页中开启了支持web App全屏模式运行时,从移动端桌面点击应用图标进入网站后,界面上看不到地址栏,这时候网页中有下拉刷新的功能时,体验会好一些。

关键词

  • mobile web app capable
  • pull to refresh
  • release updates
<html>
<head>
</head>
<body>
<div class="yxa-pull-refresh-wrap" id="yxaPullRefreshWrap">
	<div class="refresh-load-before-box" id="refreshLoadBeforeBox">
	  <span class="pull-refresh-icon"> </span><span class="pull-refresh-content" id="pullRefreshContent"></span>
	</div>
	<div class="refresh-loading-box acu-display-none" id="refreshLoadingBox">
	  <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
	  <span><?=$LanMsg['pull_to_refresh']['loading']?></span>
	</div>
</div>
<div class="yxa-content" id="yxaContent">
</div>
<script type="text/javascript">
var gTouchStartPageY = 0;
var gTouchPageYDis = 0;
var gPullRefreshTimer = null;
var gTouchTranslateY = 0;
function pullRefreshPage(){
  $("#yxaContent").on('touchstart',function(event){
    gTouchStartPageY = event.targetTouches[0].pageY;
    console.log('touchstart gTouchStartPageY:',gTouchStartPageY);
  });
  
  $("#yxaContent").on('touchmove',function(event){
    touchMovePageY = event.targetTouches[0].pageY;
    gTouchPageYDis = touchMovePageY - gTouchStartPageY;
    gTouchTranslateY = gTouchPageYDis/1.5;  
    if(gTouchPageYDis > 0){
      //alert('scrollTop:'+$(window).scrollTop()+'gTouchStartPageY:'+gTouchStartPageY);
      if($(window).scrollTop() <= 0){
        if(event.cancelable){
          event.preventDefault();
        }
      }
      //$("#yxaContent,#yxaPullRefreshWrap,#footerApp").css({'transform': 'translateY('+gTouchTranslateY+'px)'});
      $("#yxaContent,#yxaPullRefreshWrap,#footerApp").css({'transform': 'translate3d(0px,'+gTouchTranslateY+'px,0px)'});
      if(gTouchTranslateY > 35){
        $('.pull-refresh-icon').addClass('up');
        $('#pullRefreshContent').html('↑释放更新');
      }else{
        $('#pullRefreshContent').html('↓下拉刷新');
        $('.pull-refresh-icon').removeClass('up');
      }
      console.log('touchmove touchMovePageY:',touchMovePageY);
    }
  });
  $("#yxaContent").on('touchend',function(event){
    if(gTouchTranslateY > 35){
      //$("#yxaContent,#yxaPullRefreshWrap,#footerApp").css({'transform': 'translateY(30px)'});
      $("#yxaContent,#yxaPullRefreshWrap,#footerApp").css({'transform': 'translate3d(0px,30px,0px)'});
      $("#refreshLoadBeforeBox").hide();
      if(gPullRefreshTimer){
        clearTimeout(gPullRefreshTimer);
      }
      $("#refreshLoadingBox").show();
      setTimeout(function(){
        $.get('../db/goods.php?act=init&load_all=0&page='+1,function(data){
          gIsRequestPage = 1;
          gPage =1;
          dataObj = eval('('+data+')');
          //confMyListApp.confMyArr.push(dataObj.data);
          confMyListApp.confMyArr = dataObj.data;
          //confMyListApp.confMyArr = dataObj.data;
          $("#refreshLoadBeforeBox").show();
          $("#refreshLoadingBox").hide();
          gTouchTranslateY = 0;
          $('#pullRefreshContent').html('↓下拉刷新');
          $('.pull-refresh-icon').removeClass('up');
          //$("#yxaContent,#yxaPullRefreshWrap,#footerApp").css({'transform': 'translateY(0px)'});
           $("#yxaContent,#yxaPullRefreshWrap,#footerApp").css({'transform': 'translate3d(0px,0px,0px)'});
          $("#pageLoding").removeClass('acu-display-block').addClass('acu-display-none');
          $("#pageLodingOver").removeClass('acu-display-block').addClass('acu-display-none');
        })
      },500);
    }else{
      if(gTouchPageYDis != 0){
        //$("#yxaContent,#yxaPullRefreshWrap,#footerApp").css({'transform': 'translateY(0px)'});
         $("#yxaContent,#yxaPullRefreshWrap,#footerApp").css({'transform': 'translate3d(0px,0px,0px)'});
      }
    }
    gTouchPageYDis = 0;
  });
}
</script>
</boyd>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值