开始做的webview 一进去就加载了所有页面,速度慢,而且弹出其他页面的弹窗,所有改进了方法,第一次进去只执行了第一个页面,其余点击后执行。代码如下:
var aniShow = {};
//创建子页面,首个选项卡页面显示,其它均隐藏;
mui.plusReady(function() {
var self = plus.webview.currentWebview();
for (var i=0; i<1; i++) {
var sub = plus.webview.create(subpages[i].mobileHref, subpages[i].mobileHref, subpage_style, {
parentMenuId: subpages[i].id,
selfModelHref: subpages[i].mobileHref
});
if (i > 0) {
sub.hide();
}
self.append(sub);
}
});
//选项卡点击事件
mui('body').on('tap', '.mouduleBtn', function() {
var targetTab = this.getAttribute('href');
var targetTabId = this.getAttribute('id');
$(".mui-table-view-cell").css("borderBottom", "");
$(".mui-table-view-cell").css("borderRight", "");
$(".mui-table-view-cell").css("borderLeft", "");
var thisStyle = this.parentNode;
thisStyle.style.borderBottom = "2px solid #FF5511";
thisStyle.style.borderRight = "0px solid #FF5511";
thisStyle.style.borderLeft = "0px solid #FF5511";
if(targetTab == activeTab) {
return;
}
//显示目标选项卡
//若为iOS平台或非首次显示,则直接显示
/*if(mui.os.ios || aniShow[targetTab]) {
plus.webview.show(targetTab);
} else {
//否则,使用fade-in动画,且保存变量
var temp = {};
temp[targetTab] = "true";
mui.extend(aniShow, temp);
plus.webview.show(targetTab, "fade-in", 300);
}*/
var self = plus.webview.currentWebview();
var sub = plus.webview.create(targetTab, targetTab, subpage_style, {
parentMenuId: targetTabId,
selfModelHref: targetTab
});
self.append(sub);
//隐藏当前;
plus.webview.hide(activeTab);
//更改当前活跃的选项卡
activeTab = targetTab;
});