-
Notifications
You must be signed in to change notification settings - Fork 366
/
main.html
119 lines (109 loc) · 3.6 KB
/
main.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!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" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<!--标准mui.css-->
<link rel="stylesheet" href="css/mui.min.css">
<!--App自定义的css-->
<link rel="stylesheet" type="text/css" href="css/app.css"/>
</head>
<body>
<header class="mui-bar mui-bar-nav">
<a class="mui-icon mui-icon-bars mui-pull-left"></a>
<h1 class="mui-title">首页</h1>
<div class="mui-segmented-control" style="display: none;">
<a class="mui-control-item mui-active">消息</a>
<a class="mui-control-item">好友</a>
</div>
<a class="mui-icon mui-icon-plus mui-pull-right"></a>
</header>
<script src="js/mui.min.js"></script>
<script type="text/javascript" charset="utf-8">
// mui初始化
mui.init();
// 子页参数
var Index = 0;
var subpages = ['html/home.html','html/message.html','html/find.html','html/setting.html'];
var subpage_style = {
top: '45px',
bottom: '50px',
zindex:999
};
// 底部导航栏
var tw = null;
var tabbar = "html/tabbar.html";
var tabbar_style = {
height:"60px",
bottom:"0px",
background: "transparent",
zindex:9999
}
// 创建当前子页面,首个选项卡页面显示
mui.plusReady(function(){
//获取当前webview作为父webview
var self = plus.webview.currentWebview();
// 创建当前指定子页
var subIndex = plus.webview.create(subpages[Index], subpages[Index], subpage_style);
subIndex.setBounce({position:{top:"100px"},changeoffset:{top:"0px"}});
self.append(subIndex);
plus.webview.show(subIndex);
// 创建底部栏
tw = plus.webview.create(tabbar,tabbar,tabbar_style);
self.append(tw);
})
//当前激活选项
var activeTab = subpages[Index];
// 添加targetTab自定义事件监听
window.addEventListener('targetTab',function(event){
// 获得选项卡点击事件参数
var targetTitle = event.detail.targetTitle;
var targetTab = event.detail.targetTab;
// 如果为当前选项则返回
if (targetTab == activeTab) return;
// 更换标题
if (targetTab == subpages[1]) {
mui(".mui-title")[0].style.display = 'none';
mui(".mui-segmented-control")[0].style.display = 'block';
}else{
mui(".mui-title")[0].style.display = 'block';
mui(".mui-segmented-control")[0].style.display = 'none';
mui(".mui-title")[0].innerHTML = targetTitle;
}
if(!plus.webview.getWebviewById(targetTab)){
var sub = plus.webview.create(targetTab, targetTab, subpage_style);
sub.setBounce({position:{top:"100px"},changeoffset:{top:"0px"}});
plus.webview.currentWebview().append(sub);
plus.webview.show(sub,'pop-in',300);
}else{
//显示目标选项卡
plus.webview.show(targetTab);
}
// 重新加载tabbar
tw.show();
//隐藏当前;
plus.webview.hide(activeTab);
//更改当前活跃的选项卡
activeTab = targetTab;
});
//退出事件
var first=null;
mui.back = function() {
//首次按键,提示‘再按一次退出应用’
if (!first) {
first = new Date().getTime();
mui.toast('再按一次退出应用');
setTimeout(function() {
first = null;
}, 1000);
} else {
if (new Date().getTime() - first < 1000) {
plus.runtime.quit();
}
}
};
</script>
</body>
</html>