dropload.js plug-in pull-down refresh and pull-up loading methods
This article mainly introduces the use of dropload.js plug-in pull-down refresh and pull-up loading in detail. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.
The first step, download the dropload plug-in, the dropload plug-in download address official document: https://github.com/ximan/dropload
The second step , introduce the dropload.css and dropload.min.js files in the downloaded dropload plug-in into the page. Be careful to also introduce Jquery1.7 or above or Zepto. Choose one. Do not quote them both at the same time, because dropload is implemented based on jquery.
The third step, put the following code at the bottom of the page, pay attention to the bottom, otherwise the dropload plug-in will not be able to obtain the height
**基本代码结构** //#content为某个p的id var dropload = $('#content').dropload({ //scrollArea很关键,要不然加载更多不起作用 scrollArea : window, domUp : { domClass : 'dropload-up', domRefresh : '<p class="dropload-refresh">↓下拉刷新</p>', domUpdate : '<p class="dropload-update">↑释放更新</p>', domLoad : '<p class="dropload-load"><span class="loading"></span>加载中...</p>' }, domDown : { domClass : 'dropload-down', domRefresh : '<p class="dropload-refresh">↑上拉加载更多</p>', domLoad : '<p class="dropload-load"><span class="loading"></span>加载中...</p>', domNoData : '<p class="dropload-noData">暂无数据</p>' }, loadUpFn : function(me){ //下拉刷新需要调用的函数 alert("下拉刷新需要调用的函数"); //重置下拉刷新 me.resetload(); }, loadDownFn : function(me){ //上拉加载更多需要调用的函数 alert("上拉加载更多需要调用的函数"); //定时器函数,为了看出上拉加载更多效果 setTimeout(function(){ // 每次数据加载完,必须重置 me.resetload(); },1000); } });
Just view some complete examples on demand
Example one, Load bottom
<script> $(function(){ // 页数 var page = 0; // 每页展示5个 var size = 5; // dropload调用 $('.content').dropload({ scrollArea : window, loadDownFn : function(me){ page++; // 拼接HTML var result = ''; $.ajax({ type: 'GET', url: 'http://ons.me/tools/dropload/json.php?page='+page+'&size='+size,//配合后台接口 dataType: 'json', success: function(data){ var arrLen = data.length; if(arrLen > 0){ for(var i=0; i<arrLen; i++){ result += '<a class="item opacity" href="'+data[i].link+'">' +'<img src="/static/imghwm/default1.png" data-src="'+data[i].pic+'" class="lazy" alt="">' +'<h3 id="data-i-title">'+data[i].title+'</h3>' +'<span class="date">'+data[i].date+'</span>' +'</a>'; } // 如果没有数据 }else{ // 锁定 me.lock(); // 无数据 me.noData(); } // 为了测试,延迟1秒加载 setTimeout(function(){ // 插入数据到页面,放到最后面 $('.lists').append(result); // 每次数据插入,必须重置 me.resetload(); },1000); }, error: function(xhr, type){ alert('Ajax error!'); // 即使加载出错,也得重置 me.resetload(); } }); } }); }); </script>
Example two, Load top, bottom
<script> $(function(){ // 页数 var page = 0; // 每页展示10个 var size = 10; // dropload $('.content').dropload({ scrollArea : window, domUp : { domClass : 'dropload-up', domRefresh : '<p class="dropload-refresh">↓下拉刷新-自定义内容</p>', domUpdate : '<p class="dropload-update">↑释放更新-自定义内容</p>', domLoad : '<p class="dropload-load"><span class="loading"></span>加载中-自定义内容...</p>' }, domDown : { domClass : 'dropload-down', domRefresh : '<p class="dropload-refresh">↑上拉加载更多-自定义内容</p>', domLoad : '<p class="dropload-load"><span class="loading"></span>加载中-自定义内容...</p>', domNoData : '<p class="dropload-noData">暂无数据-自定义内容</p>' }, loadUpFn : function(me){ $.ajax({ type: 'GET', url: 'json/update.json', dataType: 'json', success: function(data){ var result = ''; for(var i = 0; i < data.lists.length; i++){ result += '<a class="item opacity" href="'+data.lists[i].link+'">' +'<img src="/static/imghwm/default1.png" data-src="'+data.lists[i].pic+'" class="lazy" alt="">' +'<h3 id="data-lists-i-title">'+data.lists[i].title+'</h3>' +'<span class="date">'+data.lists[i].date+'</span>' +'</a>'; } // 为了测试,延迟1秒加载 setTimeout(function(){ $('.lists').html(result); // 每次数据加载完,必须重置 me.resetload(); // 重置页数,重新获取loadDownFn的数据 page = 0; // 解锁loadDownFn里锁定的情况 me.unlock(); me.noData(false); },1000); }, error: function(xhr, type){ alert('Ajax error!'); // 即使加载出错,也得重置 me.resetload(); } }); }, loadDownFn : function(me){ page++; // 拼接HTML var result = ''; $.ajax({ type: 'GET', url: 'http://ons.me/tools/dropload/json.php?page='+page+'&size='+size, dataType: 'json', success: function(data){ var arrLen = data.length; if(arrLen > 0){ for(var i=0; i<arrLen; i++){ result += '<a class="item opacity" href="'+data[i].link+'">' +'<img src="/static/imghwm/default1.png" data-src="'+data[i].pic+'" class="lazy" alt="">' +'<h3 id="data-i-title">'+data[i].title+'</h3>' +'<span class="date">'+data[i].date+'</span>' +'</a>'; } // 如果没有数据 }else{ // 锁定 me.lock(); // 无数据 me.noData(); } // 为了测试,延迟1秒加载 setTimeout(function(){ // 插入数据到页面,放到最后面 $('.lists').append(result); // 每次数据插入,必须重置 me.resetload(); },1000); }, error: function(xhr, type){ alert('Ajax error!'); // 即使加载出错,也得重置 me.resetload(); } }); }, threshold : 50 }); }); </script>
Example three, Load multiple times
$(function(){ //利用此写法,可以限制多次加载的个数。 var timer; $('.header .ipt').on('input',function(){ var _length = $(this).val(); // 如果输入值不是数字或者是空,就跳出 if(isNaN(_length) || _length === ''){ return false; } clearTimeout(timer); timer = setTimeout(function(){//也可不用定时器 // 清空内容 $('.lists').html(''); $('.dropload-down').remove(); var counter = 0; // 每页展示4个 var num = 4; var pageStart = 0,pageEnd = 0; // dropload $('.content').dropload({ scrollArea : window, loadDownFn : function(me){ $.ajax({ type: 'GET', url: 'json/more.json', dataType: 'json', success: function(data){ var result = ''; counter++; pageEnd = num * counter; pageStart = pageEnd - num; for(var i = pageStart; i < pageEnd; i++){ result += '<a class="item opacity" href="'+data.lists[i].link+'">' +'<img src="/static/imghwm/default1.png" data-src="'+data.lists[i].pic+'" class="lazy" alt="">' +'<h3 id="data-lists-i-title">'+data.lists[i].title+'</h3>' +'<span class="date">'+data.lists[i].date+'</span>' +'</a>'; if((i + 1) >= _length || (i + 1) >= data.lists.length){ // 锁定 me.lock(); // 无数据 me.noData(); break; } } // 为了测试,延迟1秒加载 setTimeout(function(){ $('.lists').append(result); // 每次数据加载完,必须重置 me.resetload(); },1000); }, error: function(xhr, type){ alert('Ajax error!'); // 即使加载出错,也得重置 me.resetload(); } }); } }); },500); });
Example 4, Fixed layout, load top and bottom
$(function(){ // 按钮操作 $('.header .btn').on('click',function(){ var $this = $(this); if(!!$this.hasClass('lock')){ $this.attr('class','btn unlock'); $this.text('解锁'); // 锁定 dropload.lock(); $('.dropload-down').hide(); }else{ $this.attr('class','btn lock'); $this.text('锁定'); // 解锁 dropload.unlock(); $('.dropload-down').show(); } }); // dropload var dropload = $('.inner').dropload({ domUp : { domClass : 'dropload-up', domRefresh : '<p class="dropload-refresh">↓下拉刷新</p>', domUpdate : '<p class="dropload-update">↑释放更新</p>', domLoad : '<p class="dropload-load"><span class="loading"></span>加载中...</p>' }, domDown : { domClass : 'dropload-down', domRefresh : '<p class="dropload-refresh">↑上拉加载更多</p>', domLoad : '<p class="dropload-load"><span class="loading"></span>加载中...</p>', domNoData : '<p class="dropload-noData">暂无数据</p>' }, loadUpFn : function(me){ $.ajax({ type: 'GET', url: 'json/update.json', dataType: 'json', success: function(data){ var result = ''; for(var i = 0; i < data.lists.length; i++){ result += '<a class="item opacity" href="'+data.lists[i].link+'" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >' +'<img src="/static/imghwm/default1.png" data-src="'+data.lists[i].pic+'" class="lazy" alt="">' +'<h3 id="data-lists-i-title">'+data.lists[i].title+'</h3>' +'<span class="date">'+data.lists[i].date+'</span>' +'</a>'; } // 为了测试,延迟1秒加载 setTimeout(function(){ $('.lists').html(result); // 每次数据加载完,必须重置 dropload.resetload(); },1000); }, error: function(xhr, type){ alert('Ajax error!'); // 即使加载出错,也得重置 dropload.resetload(); } }); }, loadDownFn : function(me){ $.ajax({ type: 'GET', url: 'json/more.json', dataType: 'json', success: function(data){ var result = ''; for(var i = 0; i < data.lists.length; i++){ result += '<a class="item opacity" href="'+data.lists[i].link+'">' +'<img src="/static/imghwm/default1.png" data-src="'+data.lists[i].pic+'" class="lazy" alt="">' +'<h3 id="data-lists-i-title">'+data.lists[i].title+'</h3>' +'<span class="date">'+data.lists[i].date+'</span>' +'</a>'; } // 为了测试,延迟1秒加载 setTimeout(function(){ $('.lists').append(result); // 每次数据加载完,必须重置 dropload.resetload(); },1000); }, error: function(xhr, type){ alert('Ajax error!'); // 即使加载出错,也得重置 dropload.resetload(); } }); } }); });
Related recommendations:
Example details the encapsulation process of mui pull-up to load more pull-down refresh data
WeChat applet list drop-down Analysis of implementation methods of refresh and pull-up loading
The above is the detailed content of dropload.js plug-in pull-down refresh and pull-up loading methods. For more information, please follow other related articles on the PHP Chinese website!

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment
