jQuery WeUI 组件下拉刷新和滚动加载的实现(复制就可以使用)

3 篇文章 0 订阅
这是一个关于网页滚动加载和下拉刷新功能的示例代码。使用jQuery和jQuery-WeUI库,实现了内容区域的下拉刷新和无限滚动加载。当用户下拉时,页面会模拟刷新并在设定的延迟后更新内容;当用户滚动到页面底部时,会加载更多内容。此代码适用于需要动态加载数据的网页应用。
摘要由CSDN通过智能技术生成
<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
		<title>滚动加载更多</title>
		<link rel="stylesheet" href="http://cdn.bootcss.com/weui/1.1.1/style/weui.min.css">
		<link rel="stylesheet" href="http://cdn.bootcss.com/jquery-weui/1.0.1/css/jquery-weui.min.css">
		<script src="http://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
		<script src="http://cdn.bootcss.com/jquery-weui/1.0.1/js/jquery-weui.min.js"></script>
	</head>

	<body>
		<div class="content" style="background-color: #FFFFFF; width: 100%;height:88%; margin-top:40px;margin-top: 45px;position: absolute; margin-bottom:45px;padding:0px; overflow: hidden;">
			<div class="list-main-mian weui-form-preview infinite weui-pull-to-refresh" id="listwrap" style="height:100%; margin-top: 1px;overflow:auto;  z-index: 1">
				<!--下拉刷新-->
				<div class="weui-pull-to-refresh__layer" style="padding: 5px;">
					<div class="weui-pull-to-refresh__arrow"></div>
					<div class="weui-pull-to-refresh__preloader"></div>
					<div class="down">下拉刷新</div>
					<div class="up">释放刷新</div>
					<div class="refresh">正在刷新</div>
				</div>
				<div class="weui-form-preview" id="Tolist">
					<!--内容展示区域--><h1>6666</h1>
				</div>
				<div class="weui-loadmore" style="padding-bottom:30px;height:20px">
					<i class="weui-loading"></i>
					<span class="weui-loadmore__tips">正在加载</span>
				</div>
			</div>
		</div>
		<script>
			  var pages = 1;
 
   var sizes = 4;
 
   var loading = false;  //状态标记
 
   $(function () {
       loadlist();
   })
 
 //=========================下拉刷新
   $("#listwrap").pullToRefresh().on("pull-to-refresh", function () {
       setTimeout(function () {
           pages = 1;
           $("#Tolist").html("");
           loadlist();
           if (loading) loading = false;
           $("#listwrap").pullToRefreshDone(); // 重置下拉刷新
       }, 1500);   //模拟延迟
   });
 
   //============================滚动加载
   $("#listwrap").infinite().on("infinite", function () {
       if (loading) return;
       loading = true;
       pages++; //页数
    	alert("999");
       $('.weui-loadmore').show();
       setTimeout(function () {
           loadlist();
           loading = false;
       }, 2500);   //模拟延迟
   });
 
// =======加载数据loadlist();
  function loadlist() {
       var html = "";
        html += ' <div class="weui-form-preview__bd"> ';
                       html += ' <div class="weui-form-preview__item"> ';
                       html += ' <p">' + 6 + '</p> ';
                       html += ' <p">' + 6 + '</p> ';
                        html += ' <p">' + 6 + '</p> ';
                         html += ' <p">' + 6 + '</p> ';
                          html += ' <p">' + 6 + '</p> ';
                           html += ' <p">' + 6 + '</p> ';
                            html += ' <p">' + 6 + '</p> ';
                             html += ' <p">' + 6 + '</p> ';
                              html += ' <p">' + 6 + '</p> ';
                               html += ' <p">' + 6 + '</p> ';
                                html += ' <p">' + 6 + '</p> ';
                       html += ' <p">' + 6 + '</p> ';
                        html += ' <p">' + 6 + '</p> ';
                         html += ' <p">' + 6 + '</p> ';
                          html += ' <p">' + 6 + '</p> ';
                           html += ' <p">' + 6 + '</p> ';
                            html += ' <p">' + 6 + '</p> ';
                             html += ' <p">' + 6 + '</p> ';
                              html += ' <p">' + 6 + '</p> ';
                               html += ' <p">' + 6 + '</p> ';
                       html += ' </div> ';
                       html += ' </div> ';
                       $("#Tolist").append(html);
                       loading = true;
                       $(".weui-loadmore").hide();
   }
	</script>
	</body>

</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

@我不是大鹏

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值