MUI頂部選項(xiàng)卡的用法(tab-top-webview-main)詳解
前 言
MUI是一款最接近原生APP體驗(yàn)的高性能前端框架,它的比較重要的功能是:下拉刷新、側(cè)滑導(dǎo)航、滑動觸發(fā)操作菜單和頂部(底部)選項(xiàng)卡等
最近用MUI做手機(jī)app應(yīng)用的時候,遇到的小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>
<div class="d1">我是div1,下面是插入的子頁面</div> <!--我們將在這個div下邊插入子頁面-->
</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>
<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" 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">
熱點(diǎn)
</a>
</div>
</div>
</div>
</div>
<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、子頁選項(xiàng)卡的超鏈接a的data-wid=""屬性需要設(shè)置為對應(yīng)子頁選項(xiàng)卡路徑。
<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",{}) 第一個參數(shù)需要傳入一個頁面的id。需要注意的是,這個頁面id 就是我們包含頂部選項(xiàng)卡的頁面,也就是當(dāng)前我們這段js所在的頁面
new webviewGroup("tab-top-webview-main.html", {}
3、 items數(shù)組中傳入的是子頁對應(yīng)選項(xiàng)卡該導(dǎo)入的子頁面的id,有幾個子頁就添加幾個子頁,中間用逗號分隔
大家如果還有別的需求,可以去MUI網(wǎng)站上查找?guī)椭臋n http://dev.dcloud.net.cn/mui/,還有很多小功能,我會陸續(xù)更新的~~~
總結(jié)
以上所述是小編個大家介紹的MUI頂部選項(xiàng)卡的用法(tab-top-webview-main)詳解,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復(fù)大家的!
相關(guān)文章
three.js中文文檔學(xué)習(xí)之如何本地運(yùn)行詳解
這篇文章主要給大家介紹了關(guān)于three.js中文文檔學(xué)習(xí)之如何在本地運(yùn)行的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-11-11
JavaScript實(shí)現(xiàn)數(shù)據(jù)脫敏的三種解決方式
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)數(shù)據(jù)脫敏的三種解決方式,包括電話、姓名、郵箱、身份證等,有需要的小伙伴可以參考一下2024-11-11
JS實(shí)現(xiàn)簡單tab選項(xiàng)卡切換
這篇文章主要為大家詳細(xì)介紹了JS實(shí)現(xiàn)簡單tab選項(xiàng)卡切換,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-10-10
js 判斷字符串中是否包含某個字符串的實(shí)現(xiàn)代碼
工作中經(jīng)常會使用到判斷一個字符串是否包含某一個字符串,因此總結(jié)一下幾個方法,需要的朋友可以參考下2023-03-03
JavaScript實(shí)現(xiàn)字符串轉(zhuǎn)字符數(shù)組的兩種方式
在 JavaScript 的編程世界里,字符串和數(shù)組是極為常見的數(shù)據(jù)類型,在實(shí)際開發(fā)中,我們常常會遇到需要將字符串轉(zhuǎn)換為字符數(shù)組的情況,接下來,我們將深入探討如何使用 JavaScript 實(shí)現(xiàn)這一轉(zhuǎn)換,同時結(jié)合代碼示例詳細(xì)分析不同方法的特點(diǎn),需要的朋友可以參考下2025-04-04
Jvascript學(xué)習(xí)實(shí)踐案例(開發(fā)常用)
一些在Jvascript學(xué)習(xí)實(shí)踐的實(shí)例代碼,需要的朋友可以參考下2012-06-06
JavaScript日期時間與時間戳的轉(zhuǎn)換函數(shù)分享
這篇文章主要介紹了JavaScript日期時間與時間戳的轉(zhuǎn)換函數(shù)分享,本文給出兩個函數(shù)實(shí)現(xiàn)日期時間和時間戳間的轉(zhuǎn)換,需要的朋友可以參考下2015-01-01

