app html5 上拉加载分页

<script>
      //文档高度
      function getDocumentTop() {
         var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
         if (document.body) {
            bodyScrollTop = document.body.scrollTop;
         }
         if (document.documentElement) {
            documentScrollTop = document.documentElement.scrollTop;
         }
         scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
         return scrollTop;
      }
      //可视窗口高度

      function getWindowHeight() {
         var windowHeight = 0;
         if (document.compatMode == "CSS1Compat") {
            windowHeight = document.documentElement.clientHeight;
         } else {
            windowHeight = document.body.clientHeight;
         }
         return windowHeight;
      }
      //滚动条滚动高度
      function getScrollHeight() {
         var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
         if (document.body) {
            bodyScrollHeight = document.body.scrollHeight;
         }
         if (document.documentElement) {
            documentScrollHeight = document.documentElement.scrollHeight;
         }
         scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
         return scrollHeight;
      }
      window.onscroll = function () {
         //监听事件内容
         if (getScrollHeight() == getWindowHeight() + getDocumentTop()) {
            //当滚动条到底时,这里是触发内容
//            异步请求数据,局部刷新dom
//            var page =$("input[name='push_id']").val();
            var page = parseInt($("#page").val())
            paget = page+1
            var ajax = new XMLHttpRequest();
            var url="{:url('suBmenu')}";
            ajax.open('post',url,true);
            ajax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
            ajax.send('page='+paget);
            ajax.onreadystatechange=function(){
               if (ajax.readyState==4&&ajax.status==200) {
                  data=eval("("+ ajax.responseText+")");
                  if(data.status==1){
                     var html="";
                     for(var i=0; i<data.data.length; i++){
                        html+="<div class='product'>";
                        html+="<a href=''>";
                        html+="    <span class='product_img'><img src='"+data.data[i].pict_url+"' alt='' /></span>";
                        html+="<p class='product_title'><span class='tmall'></span>"+data.data[i].title+"</p>";
                        html+="<div class='product_box'>";
                        html+="<div class='product_price'>";
                        html+="<span>29.9</span>";
                        html+="<del>39.9</del>";
                        html+="</div>";
                        html+="<div class='product_value'>";
                        html+="<span>优惠券</span>"
                        html+="<span>5</span>"
                        html+="<p>领券购买</p>"
                        html+="</div>"
                        html+="</div>";
                        html+="</a>";
                        html+="</div>";
                     }
                     var div2 = document.querySelector(".list");
                     div2.insertAdjacentHTML("beforeend",html);//在调用元素内部后面添加一个子元素 即取代了最后的子元素
                     var page = parseInt($("#page").val())
                     document.getElementById("page").value=page+1;
                  }else{
                     alert(data.info);
                  }
               }
            }
         }
      }
   </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值