背景概述:javascript
mui版本:3.7.2css
單webview方式(參考資料:http://dev.dcloud.net.cn/mui/pulldown/)html
方式一:僅加載mui.min.css和mui.min.jsjava
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <title></title> <script src="js/mui.min.js"></script> <link href="css/mui.min.css" rel="stylesheet"/> </head> <body> <header class="mui-bar mui-bar-nav"> <h1 class="mui-title">標題</h1> </header> <div class="mui-content"> <!--下拉刷新容器--> <div id="refreshContainer" class="mui-scroll-wrapper" style="padding-top: 50px;"> <div class="mui-scroll"> <!--數據列表--> <ul class="mui-table-view mui-table-view-chevron"> <li class="mui-table-view-cell mui-media"> <a href="javascript:;"> <img class="mui-media-object mui-pull-left" src=""> <div class="mui-media-body"> 幸福 <p class="mui-ellipsis">能和心愛的人一塊兒睡覺,是件幸福的事情;但是,打呼嚕怎麼辦?</p> </div> </a> </li> <li class="mui-table-view-cell mui-media"> <a href="javascript:;"> <img class="mui-media-object mui-pull-left" src=""> <div class="mui-media-body"> 木屋 <p class="mui-ellipsis">想要這樣一間小木屋,夏天挫冰吃瓜,冬天圍爐取暖.</p> </div> </a> </li> <li class="mui-table-view-cell mui-media"> <a href="javascript:;"> <img class="mui-media-object mui-pull-left" src=""> <div class="mui-media-body"> CBD <p class="mui-ellipsis">烤爐模式的城,到黃昏,如同打翻的調色盤通常.</p> </div> </a> </li> <li class="mui-table-view-cell mui-media"> <a href="javascript:;"> <img class="mui-media-object mui-pull-left" src=""> <div class="mui-media-body"> 幸福 <p class="mui-ellipsis">能和心愛的人一塊兒睡覺,是件幸福的事情;但是,打呼嚕怎麼辦?</p> </div> </a> </li> <li class="mui-table-view-cell mui-media"> <a href="javascript:;"> <img class="mui-media-object mui-pull-left" src=""> <div class="mui-media-body"> 木屋 <p class="mui-ellipsis">想要這樣一間小木屋,夏天挫冰吃瓜,冬天圍爐取暖.</p> </div> </a> </li> <li class="mui-table-view-cell mui-media"> <a href="javascript:;"> <img class="mui-media-object mui-pull-left" src=""> <div class="mui-media-body"> CBD <p class="mui-ellipsis">烤爐模式的城,到黃昏,如同打翻的調色盤通常.</p> </div> </a> </li> <li class="mui-table-view-cell mui-media"> <a href="javascript:;"> <img class="mui-media-object mui-pull-left" src=""> <div class="mui-media-body"> 幸福 <p class="mui-ellipsis">能和心愛的人一塊兒睡覺,是件幸福的事情;但是,打呼嚕怎麼辦?</p> </div> </a> </li> <li class="mui-table-view-cell mui-media"> <a href="javascript:;"> <img class="mui-media-object mui-pull-left" src=""> <div class="mui-media-body"> 木屋 <p class="mui-ellipsis">想要這樣一間小木屋,夏天挫冰吃瓜,冬天圍爐取暖.</p> </div> </a> </li> <li class="mui-table-view-cell mui-media"> <a href="javascript:;"> <img class="mui-media-object mui-pull-left" src=""> <div class="mui-media-body"> CBD <p class="mui-ellipsis">烤爐模式的城,到黃昏,如同打翻的調色盤通常.</p> </div> </a> </li> </ul> </div> </div> </div> <script type="text/javascript" charset="utf-8"> mui.init(); mui.init({ pullRefresh : { container:'#refreshContainer', down : { callback: pullfreshfunc, }, up : { callback: function() { console.log('up'); var self = this; setTimeout(function() { self.endPullupToRefresh(); }, 1500); } } } }); function pullfreshfunc() { //業務邏輯代碼,好比經過ajax從服務器獲取新數據; console.log('down'); //注意,加載完新數據後,必須執行以下代碼,注意:若爲ajax請求,則需將以下代碼放置在處理完ajax響應數據以後 //沒有更多內容了,endPulldown 傳入true, 再也不執行下拉刷新 var self = this; setTimeout(function() { self.endPulldownToRefresh(); }, 1500); } </script> </body> </html>
方式二:除了加載mui.min.css和mui.min.js外,還加載mui.pullToRefresh.js和mui.pullToRefresh.material.jsios
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Hello MUI</title> <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <link rel="stylesheet" href="{$_W['siteroot']}addons/rango_coupon/static/plugin/mui-3.7.2/css/mui.min.css"> <style> html, body { background-color: #efeff4; } .mui-bar~.mui-content .mui-fullscreen { top: 44px; height: auto; } .mui-pull-top-tips { position: absolute; top: -20px; left: 50%; margin-left: -25px; width: 40px; height: 40px; border-radius: 100%; z-index: 10000; } .mui-bar~.mui-pull-top-tips { top: 24px; } .mui-pull-top-wrapper { width: 42px; height: 42px; display: block; text-align: center; background-color: #efeff4; border: 1px solid #ddd; border-radius: 25px; background-clip: padding-box; box-shadow: 0 4px 10px #bbb; overflow: hidden; /*z-index: 10000;*/ } .mui-pull-top-tips.mui-transitioning { -webkit-transition-duration: 200ms; transition-duration: 200ms; } .mui-pull-top-tips .mui-pull-loading { /*-webkit-backface-visibility: hidden; -webkit-transition-duration: 400ms; transition-duration: 400ms;*/ margin: 0; } .mui-pull-top-wrapper .mui-icon, .mui-pull-top-wrapper .mui-spinner { margin-top: 7px; } .mui-pull-top-wrapper .mui-icon.mui-reverse { /*-webkit-transform: rotate(180deg) translateZ(0);*/ } .mui-pull-bottom-tips { text-align: center; background-color: #efeff4; font-size: 15px; line-height: 40px; color: #777; /*z-index: 10000;*/ } .mui-pull-top-canvas { overflow: hidden; background-color: #fafafa; border-radius: 40px; box-shadow: 0 4px 10px #bbb; width: 40px; height: 40px; margin: 0 auto; /*z-index: 10000;*/ } .mui-pull-top-canvas canvas { width: 40px; } .mui-slider-indicator.mui-segmented-control { background-color: #efeff4; } /*.mui-table-view{margin-top: 80px;}*/ </style> </head> <body> <header class="mui-bar mui-bar-nav"> <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a> <h1 class="mui-title">選項卡切換+下拉刷新</h1> </header> <div class="mui-content"> <div id="slider" class="mui-slider mui-fullscreen"> <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"> <div class="mui-scroll"> <a class="mui-control-item mui-active" href="#item1mobile"> 推薦 </a> <a class="mui-control-item" href="#item2mobile"> 熱點 </a> <a class="mui-control-item" href="#item3mobile"> 北京 </a> <a class="mui-control-item" href="#item4mobile"> 社會 </a> <a class="mui-control-item" href="#item5mobile"> 娛樂 </a> <a class="mui-control-item" href="#item6mobile"> 科技 </a> </div> </div> <div class="mui-slider-group"> <div id="item1mobile" class="mui-slider-item mui-control-content mui-active"> <div id="scroll1" class="mui-scroll-wrapper"> <div class="mui-scroll"> <ul class="mui-table-view"> <li class="mui-table-view-cell"> 第1個選項卡子項-1 </li> <li class="mui-table-view-cell"> 第1個選項卡子項-2 </li> <li class="mui-table-view-cell"> 第1個選項卡子項-3 </li> <li class="mui-table-view-cell"> 第1個選項卡子項-4 </li> <li class="mui-table-view-cell"> 第1個選項卡子項-5 </li> <li class="mui-table-view-cell"> 第1個選項卡子項-6 </li> <li class="mui-table-view-cell"> 第1個選項卡子項-7 </li> <li class="mui-table-view-cell"> 第1個選項卡子項-8 </li> <li class="mui-table-view-cell"> 第1個選項卡子項-9 </li> <li class="mui-table-view-cell"> 第1個選項卡子項-10 </li> <li class="mui-table-view-cell"> 第1個選項卡子項-11 </li> <li class="mui-table-view-cell"> 第1個選項卡子項-12 </li> <li class="mui-table-view-cell"> 第1個選項卡子項-13 </li> <li class="mui-table-view-cell"> 第1個選項卡子項-14 </li> <li class="mui-table-view-cell"> 第1個選項卡子項-15 </li> <li class="mui-table-view-cell"> 第1個選項卡子項-16 </li> <li class="mui-table-view-cell"> 第1個選項卡子項-17 </li> <li class="mui-table-view-cell"> 第1個選項卡子項-18 </li> <li class="mui-table-view-cell"> 第1個選項卡子項-19 </li> <li class="mui-table-view-cell"> 第1個選項卡子項-20 </li> </ul> </div> </div> </div> <div id="item2mobile" class="mui-slider-item mui-control-content"> <div class="mui-scroll-wrapper"> <div class="mui-scroll"> <ul class="mui-table-view"> <li class="mui-table-view-cell"> 第2個選項卡子項-1 </li> <li class="mui-table-view-cell"> 第2個選項卡子項-2 </li> <li class="mui-table-view-cell"> 第2個選項卡子項-3 </li> <li class="mui-table-view-cell"> 第2個選項卡子項-4 </li> <li class="mui-table-view-cell"> 第2個選項卡子項-5 </li> <li class="mui-table-view-cell"> 第2個選項卡子項-6 </li> <li class="mui-table-view-cell"> 第2個選項卡子項-7 </li> <li class="mui-table-view-cell"> 第2個選項卡子項-8 </li> <li class="mui-table-view-cell"> 第2個選項卡子項-9 </li> <li class="mui-table-view-cell"> 第2個選項卡子項-10 </li> <li class="mui-table-view-cell"> 第2個選項卡子項-11 </li> <li class="mui-table-view-cell"> 第2個選項卡子項-12 </li> <li class="mui-table-view-cell"> 第2個選項卡子項-13 </li> <li class="mui-table-view-cell"> 第2個選項卡子項-14 </li> <li class="mui-table-view-cell"> 第2個選項卡子項-15 </li> <li class="mui-table-view-cell"> 第2個選項卡子項-16 </li> <li class="mui-table-view-cell"> 第2個選項卡子項-17 </li> <li class="mui-table-view-cell"> 第2個選項卡子項-18 </li> <li class="mui-table-view-cell"> 第2個選項卡子項-19 </li> <li class="mui-table-view-cell"> 第2個選項卡子項-20 </li> </ul> </div> </div> </div> <div id="item3mobile" class="mui-slider-item mui-control-content"> <div class="mui-scroll-wrapper"> <div class="mui-scroll"> <ul class="mui-table-view"> <li class="mui-table-view-cell"> 第3個選項卡子項-1 </li> <li class="mui-table-view-cell"> 第3個選項卡子項-2 </li> <li class="mui-table-view-cell"> 第3個選項卡子項-3 </li> <li class="mui-table-view-cell"> 第3個選項卡子項-4 </li> <li class="mui-table-view-cell"> 第3個選項卡子項-5 </li> <li class="mui-table-view-cell"> 第3個選項卡子項-6 </li> <li class="mui-table-view-cell"> 第3個選項卡子項-7 </li> <li class="mui-table-view-cell"> 第3個選項卡子項-8 </li> <li class="mui-table-view-cell"> 第3個選項卡子項-9 </li> <li class="mui-table-view-cell"> 第3個選項卡子項-10 </li> <li class="mui-table-view-cell"> 第3個選項卡子項-11 </li> <li class="mui-table-view-cell"> 第3個選項卡子項-12 </li> <li class="mui-table-view-cell"> 第3個選項卡子項-13 </li> <li class="mui-table-view-cell"> 第3個選項卡子項-14 </li> <li class="mui-table-view-cell"> 第3個選項卡子項-15 </li> <li class="mui-table-view-cell"> 第3個選項卡子項-16 </li> <li class="mui-table-view-cell"> 第3個選項卡子項-17 </li> <li class="mui-table-view-cell"> 第3個選項卡子項-18 </li> <li class="mui-table-view-cell"> 第3個選項卡子項-19 </li> <li class="mui-table-view-cell"> 第3個選項卡子項-20 </li> </ul> </div> </div> </div> <div id="item4mobile" class="mui-slider-item mui-control-content"> <div class="mui-scroll-wrapper"> <div class="mui-scroll"> <ul class="mui-table-view"> <li class="mui-table-view-cell"> 第4個選項卡子項-1 </li> <li class="mui-table-view-cell"> 第4個選項卡子項-2 </li> <li class="mui-table-view-cell"> 第4個選項卡子項-3 </li> <li class="mui-table-view-cell"> 第4個選項卡子項-4 </li> <li class="mui-table-view-cell"> 第4個選項卡子項-5 </li> <li class="mui-table-view-cell"> 第4個選項卡子項-6 </li> <li class="mui-table-view-cell"> 第4個選項卡子項-7 </li> <li class="mui-table-view-cell"> 第4個選項卡子項-8 </li> <li class="mui-table-view-cell"> 第4個選項卡子項-9 </li> <li class="mui-table-view-cell"> 第4個選項卡子項-10 </li> <li class="mui-table-view-cell"> 第4個選項卡子項-11 </li> <li class="mui-table-view-cell"> 第4個選項卡子項-12 </li> <li class="mui-table-view-cell"> 第4個選項卡子項-13 </li> <li class="mui-table-view-cell"> 第4個選項卡子項-14 </li> <li class="mui-table-view-cell"> 第4個選項卡子項-15 </li> <li class="mui-table-view-cell"> 第4個選項卡子項-16 </li> <li class="mui-table-view-cell"> 第4個選項卡子項-17 </li> <li class="mui-table-view-cell"> 第4個選項卡子項-18 </li> <li class="mui-table-view-cell"> 第4個選項卡子項-19 </li> <li class="mui-table-view-cell"> 第4個選項卡子項-20 </li> </ul> </div> </div> </div> <div id="item5mobile" class="mui-slider-item mui-control-content"> <div class="mui-scroll-wrapper"> <div class="mui-scroll"> <ul class="mui-table-view"> <li class="mui-table-view-cell"> 第5個選項卡子項-1 </li> <li class="mui-table-view-cell"> 第5個選項卡子項-2 </li> <li class="mui-table-view-cell"> 第5個選項卡子項-3 </li> <li class="mui-table-view-cell"> 第5個選項卡子項-4 </li> <li class="mui-table-view-cell"> 第5個選項卡子項-5 </li> <li class="mui-table-view-cell"> 第5個選項卡子項-6 </li> <li class="mui-table-view-cell"> 第5個選項卡子項-7 </li> <li class="mui-table-view-cell"> 第5個選項卡子項-8 </li> <li class="mui-table-view-cell"> 第5個選項卡子項-9 </li> <li class="mui-table-view-cell"> 第5個選項卡子項-10 </li> <li class="mui-table-view-cell"> 第5個選項卡子項-11 </li> <li class="mui-table-view-cell"> 第5個選項卡子項-12 </li> <li class="mui-table-view-cell"> 第5個選項卡子項-13 </li> <li class="mui-table-view-cell"> 第5個選項卡子項-14 </li> <li class="mui-table-view-cell"> 第5個選項卡子項-15 </li> <li class="mui-table-view-cell"> 第5個選項卡子項-16 </li> <li class="mui-table-view-cell"> 第5個選項卡子項-17 </li> <li class="mui-table-view-cell"> 第5個選項卡子項-18 </li> <li class="mui-table-view-cell"> 第5個選項卡子項-19 </li> <li class="mui-table-view-cell"> 第5個選項卡子項-20 </li> </ul> </div> </div> </div> <div id="item6mobile" class="mui-slider-item mui-control-content"> <div class="mui-scroll-wrapper"> <div class="mui-scroll"> <ul class="mui-table-view"> <li class="mui-table-view-cell"> 第6個選項卡子項-1 </li> <li class="mui-table-view-cell"> 第6個選項卡子項-2 </li> <li class="mui-table-view-cell"> 第6個選項卡子項-3 </li> <li class="mui-table-view-cell"> 第6個選項卡子項-4 </li> <li class="mui-table-view-cell"> 第6個選項卡子項-5 </li> <li class="mui-table-view-cell"> 第6個選項卡子項-6 </li> <li class="mui-table-view-cell"> 第6個選項卡子項-7 </li> <li class="mui-table-view-cell"> 第6個選項卡子項-8 </li> <li class="mui-table-view-cell"> 第6個選項卡子項-9 </li> <li class="mui-table-view-cell"> 第6個選項卡子項-10 </li> <li class="mui-table-view-cell"> 第6個選項卡子項-11 </li> <li class="mui-table-view-cell"> 第6個選項卡子項-12 </li> <li class="mui-table-view-cell"> 第6個選項卡子項-13 </li> <li class="mui-table-view-cell"> 第6個選項卡子項-14 </li> <li class="mui-table-view-cell"> 第6個選項卡子項-15 </li> <li class="mui-table-view-cell"> 第6個選項卡子項-16 </li> <li class="mui-table-view-cell"> 第6個選項卡子項-17 </li> <li class="mui-table-view-cell"> 第6個選項卡子項-18 </li> <li class="mui-table-view-cell"> 第6個選項卡子項-19 </li> <li class="mui-table-view-cell"> 第6個選項卡子項-20 </li> </ul> </div> </div> </div> </div> </div> </div> <!-- <script src="../js/mui.min.js"></script> <script src="../js/mui.pullToRefresh.js"></script> <script src="../js/mui.pullToRefresh.material.js"></script>--> <script type="text/javascript" src="{$_W['siteroot']}addons/rango_coupon/static/plugin/mui-3.7.2/js/mui.min.js"></script> <script type="text/javascript" src="{$_W['siteroot']}addons/rango_coupon/static/plugin/mui-3.7.2/js/mui.pullToRefresh.js"></script> <script type="text/javascript" src="{$_W['siteroot']}addons/rango_coupon/static/plugin/mui-3.7.2/js/mui.pullToRefresh.material.js"></script> <script> mui.init(); (function($) { //阻尼係數 var deceleration = mui.os.ios?0.003:0.0009; $('.mui-scroll-wrapper').scroll({ bounce: false, indicators: true, //是否顯示滾動條 deceleration:deceleration }); $.ready(function() { //循環初始化全部下拉刷新,上拉加載。 $.each(document.querySelectorAll('.mui-slider-group .mui-scroll'), function(index, pullRefreshEl) { $(pullRefreshEl).pullToRefresh({ down: { callback: function() { var self = this; setTimeout(function() { var ul = self.element.querySelector('.mui-table-view'); ul.insertBefore(createFragment(ul, index, 10, true), ul.firstChild); self.endPullDownToRefresh(); }, 5000); } }, up: { callback: function() { var self = this; setTimeout(function() { var ul = self.element.querySelector('.mui-table-view'); ul.appendChild(createFragment(ul, index, 5)); self.endPullUpToRefresh(); }, 1000); } } }); }); var createFragment = function(ul, index, count, reverse) { var length = ul.querySelectorAll('li').length; var fragment = document.createDocumentFragment(); var li; for (var i = 0; i < count; i++) { li = document.createElement('li'); li.className = 'mui-table-view-cell'; li.innerHTML = '第' + (index + 1) + '個選項卡子項-' + (length + (reverse ? (count - i) : (i + 1))); fragment.appendChild(li); } return fragment; }; }); })(mui); </script> </body> </html>
兩種方式都差很少,樣式不一樣而已web