listloading is a mobile pull-down and pull-down component that loads more components. It mainly relies on components developed based on iscroll.js v5.1.2. The basic library can use jquery.js or zepto.js to operate dom nodes. Currently, I use zepto.js as the basic library to operate dom, which exists in the form of a jquery plug-in. . If you don't want to use it as a plug-in, you only need to transplant listloading directly into the library you need. listloading is mainly designed for mobile terminals. When using the browser's built-in scrolling, the user experience is very unfriendly and far different from Android and iOS, so I choose iscroll.js. Its implementation is to use css3 animation translate 3D conversion to achieve the scrolling effect. , the transform attribute uses hardware acceleration, and the performance method is greatly improved. Support Node introduction and require introduction.
npm install listloading
< div id =" listloading " >
< div >
< ul id =" order-list " > </ ul >
</ div >
</ div >
The structure is the same as that created by iscroll, but the specified created element node must specify an ID, because the publish and subscribe mode in the component requires an identification. Because iscroll must first set the height before the node element is created, otherwise it will result in the inability to scroll; after iscroll is created, it is assigned to the first child element for scrolling, so the pull-up and pull-down refresh of listloading are also appended to the first child element. , in fact, just imagine the first child element as the body in html.
< script src = "../src/jslib/zepto.min.js" > </ script >
< script src = "../src/jslib/iscroll.js" > < / script >
< script src = "../build/ listloading .min.js" > </ script >
var listloading = require ( ' listloading ' ) ;
var m = 3 ;
var n = 0 ;
var hei = $ ( window ) . height ( ) ;
// 创建iscroll之前必须要先设置父元素的高度,否则无法拖动iscroll
$ ( '# listloading , . listloading Class' ) . height ( hei ) ;
// 模板
var createHtml = function ( ) {
var __html = '' ;
for ( var i = 0 ; i < 15 ; i ++ ) {
var now = new Date ( ) . getTime ( ) ;
now = new Date ( now + i * 1000000 ) ;
__html += '<li><span class="icon"></span><p class="title"><time class="r">' + now . getHours ( ) + ':' + now . getMinutes ( ) + ':' + now . getSeconds ( ) + '</time> listloading ' + ( n ++ ) + '</p><p class="text">移动端上拉下拉刷新组件...</li>' ;
}
return __html ;
}
// demo
var listloading = new listloading ( '# listloading ' , {
disableTime : true , // 是否需要显示时间
pullUpAction : function ( cb ) { // 上拉加载更多
m -- ;
var flg = false ;
var __html = createHtml ( ) ;
if ( m < 1 ) {
flg = true ;
} else {
$ ( '#order-list' ) . append ( __html ) ;
}
// 数据加载完毕需要返回 end为true则为全部数据加载完毕
cb ( flg ) ;
} ,
pullDownAction : function ( cb ) { // 下拉刷新
// true则为默认加载 false为下拉刷新
if ( flg ) {
console . log ( '默认加载' ) ;
}
m = 3 ;
var __html = createHtml ( ) ;
$ ( '#order-list' ) . html ( __html ) ;
// 执行完执行方法之后必须执行回调 回调的作用是通知默认加载已经全部执行完毕,程序需要去创建iscroll或者做下拉刷新动作
cb ( ) ;
} ,
// iscroll的API
iscrollOptions : {
//
}
} ) ;
// 点击事件
listloading . evt ( 'li' , 'click' , function ( dom ) {
dom . remove ( ) ;
// $('#order-list').append(createHtml());
listloading . refresh ( ) ;
} ) ;
// demo
// var k = 3;
// var listloading Class = new listloading ('. listloading Class', {
// pullUpAction : function(cb){ //上拉加载更多
// k--;
// var flg = false;
// var __html = createHtml();
// if(k < 1){
// flg = true;
// }else{
// $('# listloading Class-order-list').append(__html);
// }
// // 数据加载完毕需要返回 end为true则为全部数据加载完毕
// cb(flg);
// },
// pullDownAction : function(cb, flag){ //下拉刷新
// // flag 为true 第一次加载
// if (flag) {
// // dosomething...
// }
// k = 3;
// var __html = createHtml();
// $('# listloading Class-order-list').html(__html);
// // 执行完执行方法之后必须执行回调 回调的作用是通知默认加载已经全部执行完毕,程序需要去创建iscroll或者做下拉刷新动作
// cb();
// }
// });
The initialization will be executed once, mainly to create iscroll, and then executed after each pull-down refresh. When your program is executed in the method, a callback function needs to be executed to inform that all programs have been executed. listloading will automatically call iscroll. Refresh function, callback does not need to pass parameters.
options . pullDownAction = function ( cb , flag ) { // 下拉刷新
// flag 为true 第一次加载
if ( flag ) {
// dosomething...
}
// 执行完执行方法之后必须执行回调
cb ( ) ;
}
Each pull-up is executed after more loading is completed. Similarly, after executing your program, a callback function needs to be executed. A Boolean value needs to be called back in the callback. If it is true, then all the loads have been completed, and the pull-up has been completed.
options . pullUpAction = function ( cb ) { // 上拉加载更多
... . .
// 执行完执行方法之后必须执行回调 true为上拉到底
cb ( true ) ;
}
listloading . destroy ( ) ;
If there are additions or deletions of nodes in the scroll area, this method needs to be called after the operation is completed.
listloading . refresh ( ) ;
true pull-down display time, the time since the last refresh
options . disableTime = true
options . upLoadmoretxt = '上拉加载更多文字' ; // 里面可以放html标签
options . pullDrefreshtxt = '下拉刷新文字' ; // 里面可以放html标签
options . loadertxt = '正在加载中文字' ; // 里面可以放html标签
options . Realtimetxt = '松开刷新文字' ; // 里面可以放html标签
options . loaderendtxt = '已经全部加载完毕文字' ; // 里面可以放html标签
options . iscrollOptions = { } ;
listloading
├────build
| └── listloading . js // 源文件
├────demos
| └── . ... // demo字体样式
├────dist
| | ──css
| | └── listloading . min . css // 压缩css
| └──js
| └── listloading . min . js // 压缩js源文件
├────src
| | ──css
| | └──base . css // 基础base样式
| | ──fontface
| | └── . . . // 字体文件
| | ──images
| | └── . . . // demo图片
| | ──jslib
| | └── . . . // 第三方库
Special thanks to microlv for its technical support and code contribution.
Copyright (c) gtdalp. All rights reserved.
Licensed under the MIT License.