上拉/下拉动态加载

用移动浏览器打开查看demo或用PC上的chrome开发人员工具Emulation来模拟查看。滚动到底端/顶端时,继续上拉/下拉会自动动态加载内容

Source
Output
QRCode
<!doctype html> <html> <head> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="apple-touch-fullscreen" content="yes"> <title>上拉/下拉动态加载</title> <link rel="stylesheet" type="text/css" href="//g.alicdn.com/kissy/k/5.0.1/scroll-view/assets/dpl.css"> <script type="text/javascript" src="//g.alicdn.com/kissy/k/5.0.1/seed-debug.js" data-config="{combine:true}"></script> <style> body{ background: #fff; } body, ul, li { padding: 0; margin: 0; border: 0; } html, body { font-size: 12px; -webkit-text-size-adjust: none; font-family: helvetica; overflow: hidden; } #header { position: absolute; top: 0; left: 0; width: 100%; height: 45px; line-height: 45px; background-color: #00A0E9; padding: 0; color: #eee; font-size: 20px; text-align: center; } #header a { color: #f3f3f3; text-decoration: none; font-weight: bold; text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.5); } #footer { position: absolute; bottom: 0; left: 0; width: 100%; height: 48px; background-color: #888; padding: 0; border-top: 1px solid #444; } #wrapper { position: absolute; top: 45px; bottom: 48px; left: 0; width: 100%; background: #555; overflow: auto; } .ks-ie6 #wrapper { height: expression(document.documentElement.clientHeight-48-45); } #wrapper p { margin: 0; padding: 0 10px; height: 40px; line-height: 40px; border-bottom: 1px solid #ccc; border-top: 1px solid #fff; background-color: #fafafa; font-size: 14px; } </style> </head> <body> <div id="header">KISSY ScrollView</div> <div id="wrapper" class="ks-scroll-view"> <div class="ks-scroll-view-content" id="thelist"> </div> </div> <div id="footer"></div> <script> require(['node', 'scroll-view', 'scroll-view/plugin/scrollbar', 'scroll-view/plugin/pull-to-refresh'], function ($, ScrollView, ScrollbarPlugin, PullToRefresh) { var str = '', num = 1; for (; num < 40; num++) { str += '<p>line ' + num + '</p>' } $('#thelist').html(str); var scrollView = new ScrollView({ srcNode: '#wrapper', plugins: [ ScrollbarPlugin, new PullToRefresh({ pullUpLoadFn: function (callback) { //滚动到低端后继续上拉将进入这个函数 setTimeout(function () { scrollView.get('contentEl') .append('<p>line ' + num++ + '</p>'); scrollView.sync(); callback(); }, 500); }, pullingUpHtml : '上拉刷新', releasingUpHtml : '松手加载', loadingUpHtml : '正在努力加载...', pullDownLoadFn : function(callback){ //滚动到顶端后继续下拉将进入这个函数 setTimeout(function () { scrollView.get('contentEl') .prepend('<p>line ' + num++ + '</p>'); scrollView.sync(); callback(); }, 500); } }) ] }).render(); }); </script> </body> </html>