The use of automatic pull-down loading for paging is increasing. Compared with the traditional paging method, the paging user experience is better and the layout is simpler. Currently in use and learning ...... JQuery Plugin: iScroll
Page Layout:
Pull down to refresh...
Load more...
Page turning is to pass the page number to the general Handler through ajax requests. The paging data obtained in the general handler is returned as a json array object.
Pull-down Refresh:
/*** Pull-down refresh (custom implementation of this method) * myScroll. refresh (); // call the interface update Method */function pullDownAction () {setTimeout (function () {var el, li, I; el = document. getElementById ('thelist '); // ================================================ =====$. ajax ({type: "GET", url: "LoadMore. ashx ", data: {page: generatedCount}, dataType:" json ", success: function (data) {var json = data; $ (json ). each (function () {li = document. c ReateElement ('lil'); // li. innerText = 'generated row' + (++ generatedCount); li. innerHTML = ''; el. insertBefore (li, el. childNodes [0]) ;}}}); myScroll. refresh (); // after the data is loaded, call the interface update method Remember to refresh when contents are loaded (ie: on ajax completion)}, 1000 ); // <-- Simulate network congestion, remove setTimeout from production! }
Pull up and refresh
Function pullUpAction () {setTimeout (function () {var el, li, I; el = document. getElementById ('thelist '); // ================================================ =====$. ajax ({type: "GET", url: "LoadMore. ashx ", data: {page: generatedCount}, dataType:" json ", success: function (data) {var json = data; $ (json ). each (function () {li = document. createElement ('lil'); // li. innerText = 'generated row' + (++ Generated Count); li. innerHTML = '; el. insertBefore (li, el. childNodes [0]) ;}}); // ================================================ ===== myScroll. refresh (); // after the data is loaded, call the interface update method Remember to refresh when contents are loaded (ie: on ajax completion)}, 1000 ); // <-- Simulate network congestion, remove setTimeout from production! }
Initialization
/*** Initialize the iScroll control */function loaded () {pullDownEl = document. getElementById ('pulldown'); pullDownOffset = pullDownEl. offsetHeight; pullUpEl = document. getElementById ('pullup'); pullUpOffset = pullUpEl. offsetHeight; myScroll = new iScroll ('wrapper', {scrollbarClass: 'myrollbar',/* important style */useTransition: false, topOffset: pullDownOffset, onRefresh: function () {if (pullDownEl. className. match ('Loading') {pullDownEl. className = ''; pullDownEl. querySelector ('. pullDownLabel '). innerHTML = 'pull-down refresh... ';} else if (pullUpEl. className. match ('loading') {pullUpEl. className = ''; pullUpEl. querySelector ('. pullUpLabel '). innerHTML = 'pull up to load more... ';}}, onScrollMove: function () {if (this. y> 5 &&! PullDownEl. className. match ('flip') {pullDownEl. className = 'flip'; pullDownEl. querySelector ('. pullDownLabel '). innerHTML = 'start updating... '; this. minScrollY = 0;} else if (this. y <5 & pullDownEl. className. match ('flip') {pullDownEl. className = ''; pullDownEl. querySelector ('. pullDownLabel '). innerHTML = 'pull-down refresh... '; this. minScrollY =-pullDownOffset;} else if (this. y <(this. maxScrollY-5 )&&! PullUpEl. className. match ('flip') {pullUpEl. className = 'flip'; pullUpEl. querySelector ('. pullUpLabel '). innerHTML = 'start updating... '; this. maxScrollY = this. maxScrollY;} else if (this. y> (this. maxScrollY + 5) & pullUpEl. className. match ('flip') {pullUpEl. className = ''; pullUpEl. querySelector ('. pullUpLabel '). innerHTML = 'pull up to load more... '; this. maxScrollY = pullUpOffset ;}}, onScrollEnd: function () {if (PullDownEl. className. match ('flip') {pullDownEl. className = 'loading'; pullDownEl. querySelector ('. pullDownLabel '). innerHTML = 'loading... '; pullDownAction (); // Execute custom function (ajax call ?)} Else if (pullUpEl. className. match ('flip') {pullUpEl. className = 'loading'; pullUpEl. querySelector ('. pullUpLabel '). innerHTML = 'loading... '; pullUpAction (); // Execute custom function (ajax call ?) }}}); SetTimeout (function () {document. getElementById ('wrapper '). style. left = '0';}, 800);} // initialize the document bound to the iScroll control. addEventListener ('touchmove ', function (e) {e. preventDefault () ;}, false); document. addEventListener ('domainloaded', loaded, false );