栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

H5下拉加载

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

H5下拉加载

html代码
class="name">{$vo.name} class="num">{$vo.vote_num|num_format_w=###}人气
加载中...
js代码
//下拉加载更多
    $(function () {
 var pageIndex = 1;
 //获取滚动条当前的位置
 function getScrollTop() {
     var scrollTop = 0;
     if (document.documentElement && document.documentElement.scrollTop) {
  scrollTop = document.documentElement.scrollTop;
     } else if (document.body) {
  scrollTop = document.body.scrollTop;
     }
     return scrollTop;
 }

 //获取当前可视范围的高度
 function getClientHeight() {
     var clientHeight = 0;
     if (document.body.clientHeight && document.documentElement.clientHeight) {
  clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight);
     } else {
  clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
     }
     return clientHeight;
 }

 //获取文档完整的高度
 function getScrollHeight() {
     return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
 }

 window.onscroll = function () {
     if (getScrollTop() + getClientHeight() == getScrollHeight()) {
  $("#jiazaizhong").removeClass("none");
  pageIndex++;
  $.ajax({
      url: url + "index.php/index/index",
      type: "post",
      dataType: "json",
      async: false,
      data: {
   vote_item_id: "1",
   page: pageIndex,
   api: "1"
      },
      success: function (res) {
      
   var cont = (res.data.total_record) / (res.data.page_size);
   let obj2 = res.data;
   
   if (parseInt(cont) == cont) {
var cont2 = cont
   } else {
var cont2 = parseInt(cont) + 1
   }
   if (pageIndex <= cont2) {
for (var i = 0; i < res.data.page_size; i++) {
    $(".player_box").append(
 'n' +
 'n' +
 ' + obj2[i].uid + "/vote_item_id/" + obj2[i].vote_item_id + ".html" + '">n' +
 'n' +
 ' + obj2[i].pic_arr[0] + '">n' +
 'n' +
 '' + obj2[i].user_num + 'n' +
 'n' +
 'n' +
 'n' +
 '' + obj2[i].name + 'n' +
 '' + obj2[i].vote_num + '人气n' +
 'n' +
 'n' +
 'n'
    );
}
   } else {
$("#jiazaizhong").text("到底了...")
   }
      },
      error: function () {
   console.log("请求失败")
      }
  })
     }
 };
    });
转载请注明:文章转载自 www.mshxw.com
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号