结合jquery mobile简单实现如下
<!DOCTYPE html> <html> <head> <title>jQuery Mobile Application</title> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.css" /> <script type="text/javascript" src="iscroll.js"></script> <script src="http://code.jquery.com/jquery-1.5.2.min.js"></script> <script src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"> </script> <script type="text/javascript"> var myScroll, pullDownEl, pullDownOffset, pullUpEl, pullUpOffset, generatedCount = 0; function pullDownAction () { $.ajax({ url:"data.php", dataType:"text", success:function(data){ var el, li, i; el = document.getElementById('thelist'); data = JSON.parse(data); for (i=0; i<data.length; i++) { li = document.createElement('li'); li.innerText = data[i]; li.className = 'ui-li ui-li-static ui-body-c'; el.insertBefore(li, el.childNodes[0]); } myScroll.refresh(); // Remember to refresh when contents are loaded (ie: on ajax completion) } })(); } function pullUpAction () { $.ajax({ url:"data.php", dataType:"text", success:function(data){ var el, li, i; el = document.getElementById('thelist'); data = JSON.parse(data); for (i=0; i<data.length; i++) { li = document.createElement('li'); li.innerText = data[i]; li.className = 'ui-li ui-li-static ui-body-c'; el.appendChild(li, el.childNodes[0]); } myScroll.refresh(); // Remember to refresh when contents are loaded (ie: on ajax completion) } })(); } function loaded() { pullDownEl = document.getElementById('pullDown'); pullDownOffset = pullDownEl.offsetHeight; pullUpEl = document.getElementById('pullUp'); pullUpOffset = pullUpEl.offsetHeight; myScroll = new iScroll('wrapper', { useTransition: true, topOffset: pullDownOffset, onRefresh: function () { if (pullDownEl.className.match('loading')) { pullDownEl.className = ''; pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Pull down to 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 = 'Release to refresh...'; this.minScrollY = 0; } else if (this.y < 5 && pullDownEl.className.match('flip')) { pullDownEl.className = ''; pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Pull down to refresh...'; this.minScrollY = -pullDownOffset; } else if (this.y < (this.maxScrollY - 5) && !pullUpEl.className.match('flip')) { pullUpEl.className = 'flip'; pullUpEl.querySelector('.pullUpLabel').innerHTML = 'Release to refresh...'; 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.cssText = ""; }, 0); } document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false); document.addEventListener('DOMContentLoaded', function () { setTimeout(loaded, 200); }, false); </script> <style type="text/css" media="all"> #pullDown, #pullUp { height:40px; line-height:40px; border-bottom:1px solid #ccc; padding: 5px 10px; font-weight:bold; font-size:14px; color:#888; } #pullDown .pullDownIcon, #pullUp .pullUpIcon { display:block; float:left; width:40px; height:40px; background:url(pull-icon@2x.png) 0 0 no-repeat; -webkit-background-size:40px 80px; background-size:40px 80px; -webkit-transition-property:-webkit-transform; -webkit-transition-duration:250ms; } #pullDown.flip .pullDownIcon { -webkit-transform:rotate(-180deg) translateZ(0); } #pullUp.flip .pullUpIcon { -webkit-transform:rotate(0deg) translateZ(0); } #pullDown.loading .pullDownIcon, #pullUp.loading .pullUpIcon { background-position:0 100%; -webkit-transform:rotate(0deg) translateZ(0); -webkit-transition-duration:0ms; -webkit-animation-name:loading; -webkit-animation-duration:2s; -webkit-animation-iteration-count:infinite; -webkit-animation-timing-function:linear; } </style> </head> <body> <section id="page1" data-role="page"> <header data-role="header"><h1>jQuery Mobile</h1></header> <div data-role="content" id="content"> <div id="wrapper"> <div id="scroller"> <div id="pullDown"> <span class="pullDownIcon"></span><span class="pullDownLabel">Pull down to refresh...</span> </div> <ul id="thelist" data-role="listview"> <li>Pretty row 1</li> <li>Pretty row 2</li> <li>Pretty row 3</li> <!-- <li>Pretty row 4</li> <li>Pretty row 5</li> <li>Pretty row 6</li> <li>Pretty row 7</li> <li>Pretty row 8</li> <li>Pretty row 9</li> <li>Pretty row 10</li> <li>Pretty row 11</li> --> </ul> <div id="pullUp"> <span class="pullUpIcon"></span><span class="pullUpLabel">Pull up to refresh...</span> </div> </div> </div> </div> <footer data-role="footer"><h1>O'Reilly</h1></footer> </section> </body> </html>
相关推荐
iScroll下拉刷新上滑加载; 使用经典插件iScroll4稍作封装,采用ajax请求数据,实现移动端列表页的功能; 1.下拉刷新当前列表页数据; 2.上滑加载更多列表数据; iScroll4简介: iScroll 4 这个版本完全重写了...
iScroll 5下拉刷新。 iScroll 5 更新之后的pull-to-refresh的demo没了,无奈,google下一个国外程序员写的上下拉刷新,自己精简了下,只保留了下拉刷新。
在IT行业中,iscroll5是一款广泛使用的轻量级滚动插件,特别适合处理移动设备上的滚动事件。...在压缩包中的"iscroll下拉刷新自写"文件,可能包含了实现这一功能的详细代码和示例,可以作为学习和参考的资源。
**iscroll 下拉刷新** `iscroll` 是一个轻量级、高性能的JavaScript滚动库,由Matteo Spinelli开发,广泛应用于移动端Web应用中,为网页提供平滑的滚动效果,同时也支持下拉刷新(Pull-to-Refresh)和上拉加载更多...
本文将深入探讨jQuery iScroll下拉刷新插件的使用方法、原理及其实现细节。 首先,我们要理解jQuery iScroll是什么。iScroll是由Matteo Spinelli开发的一个JavaScript滚动库,它提供了一种优雅的方式来处理页面滚动...
4. **下拉刷新与上拉加载**:iscroll内置支持下拉刷新和上拉加载功能,可以轻松地与AJAX或其他数据获取方式结合,实现内容的动态加载。 5. **多视图模式**:iscroll支持水平和垂直滚动,甚至可以同时启用两者,以...
iscroll5的下拉实现,修改了iscroll-zoom.js(在原有版本上多了缩放功能的版本)的部分代码,具体修改可见http://www.duanzhihe.com/1045.html。欢迎再交流与讨论
在"iScroll 实例:下拉刷新,滚动翻页"这个主题中,我们将深入探讨如何利用iScroll实现下拉刷新和滚动翻页功能,这两种功能在现代Web应用中极为常见,特别是在内容丰富的列表或者无限滚动的应用场景中。 **下拉刷新...