MUI是一款最接近原生APP體驗的高效能前端框架,它的比較重要的功能是:下拉刷新、側滑導航、滑動觸發操作選單和頂部(底部)標籤等。
最近用MUI做手機app應用程式的時候,遇到的小bug。順便研究了一下這個tab-top-webview-main,這裡來跟大家分享一下。
1主頁代碼
<!doctype html> <html> <head> <meta charset="UTF-8"> <title></title> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <link href="css/mui.min.css" rel="external nofollow" rel="external nofollow" rel="stylesheet" /> <style type="text/css"> .d1{ width: 100%; height: 50px; text-align: center; line-height: 50px; background-color: #CCCCCC; } </style> </head> <body> <p class="d1">我是p1,下面是插入的子页面</p> <!--我们将在这个p下边插入子页面--> </body> <script src="js/mui.min.js"></script> <script type="text/javascript"> mui.init({ subpages:[{ //下边是初始化,然后这个页面显示我们将插入的页面 url:"tab-top-webview-main.html", id:"tab-top-webview-main.html", styles:{ top:"50px", bottom:"0px" } }] }) </script> </html>
2子頁代碼
<!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="css/mui.min.css" rel="external nofollow" rel="external nofollow" > </head> <body> <p class="mui-content"> <p id="slider" class="mui-slider mui-fullscreen"> <p id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"> <p class="mui-scroll"> <a class="mui-control-item mui-active" href="#item1mobile" rel="external nofollow" rel="external nofollow" data-wid="tab-top-subpage-1.html"> 推荐 </a> <a class="mui-control-item" href="#item2mobile" rel="external nofollow" data-wid="tab-top-subpage-2.html"> 热点 </a> </p> </p> </p> </p> <script src="js/mui.min.js"></script> <script src="js/webviewGroup.js" type="text/javascript" charset="utf-8"></script> <script> mui.init(); mui.plusReady(function() { var group = new webviewGroup("tab-top-webview-main.html", { items: [{ id: "tab-top-subpage-1.html", //这是子页1的路径 url: "tab-top-subpage-1.html", extras: {} }, { id: "tab-top-subpage-2.html", //这是子页2的路径 url: "tab-top-subpage-2.html", extras: {} }], onChange: function(obj) { var c = document.querySelector(".mui-control-item.mui-active"); if(c) { c.classList.remove("mui-active"); } document.querySelector(".mui-scroll .mui-control-item:nth-child(" + (parseInt(obj.index) + 1) + ")").classList.add("mui-active"); } }); mui(".mui-scroll").on("tap", ".mui-control-item", function(e) { var wid = this.getAttribute("data-wid"); group.switchTab(wid); }); }); mui.back = function() { var _self = plus.webview.currentWebview(); _self.close("auto"); } </script> </body> </html>
3代碼解釋
var group = new webviewGroup("tab-top-webview-main.html", { items: [{ id: "tab-top-subpage-1.html", //这是子页1的路径 url: "tab-top-subpage-1.html", extras: {} }, { id: "tab-top-subpage-2.html", //这是子页2的路径 url: "tab-top-subpage-2.html", extras: {} }] })
1、子頁選項卡的超連結a的data- wid=""屬性需要設定為對應子頁選項卡路徑。
<a class="mui-control-item mui-active" href="#item1mobile" rel="external nofollow" rel="external nofollow" data-wid="tab-top-subpage-1.html"> 推荐 </a>
2、這裡,new webviewGroup("tab-top-webview-main.html",{}) 第一個參數需要傳入一個頁面的id。要注意的是,這個頁面id 就是我們包含頂部選項卡的頁面,也就是目前我們這段js所在的頁面
new webviewGroup("tab-top-webview-main.html", {}
3、 items數組中傳入的是子頁對應選項卡該導入的子頁面的id,有幾個子頁就加入幾個子頁,中間用逗號分隔
相關推薦:
以上是MUI頂部選項卡的用法詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!