以下就是主页的代码
<body>
<header class="mui-bar mui-bar-nav" style="height: 46px;">
<a id="locationimg" class="mui-icon mui-icon-location " style="color: gray;font-size: 19px;line-height: 25px;">
</a>
<label style="font-size: 14px;">成都</label>
<h1 id="title" class="mui-title" style="font-size: 22px;line-height: 50px;">首页</h1>
<a href="#plus.device.dial" id="phone" onclick="CallPhone()" class="mui-icon mui-icon-phone " style="color: #29b16f;font-size: 22px;line-height: 25px;float: right;">
</a>
</header>
<nav class="mui-bar mui-bar-tab">
<a id="defaultTab" class="mui-tab-item mui-active" href="index.html">
<span class="mui-icon iconfont icon-home"></span>
<span class="mui-tab-label">首页</span>
</a>
<a class="mui-tab-item" href="Inspiration.html">
<span class="mui-icon iconfont icon-img"></span>
<span class="mui-tab-label">灵感</span>
</a>
<a id="myDecorate" class="mui-tab-item" href="MyDecorate.html">
<span class="mui-icon iconfont icon-brush"></span>
<span class="mui-tab-label">我来装</span>
</a>
<a class="mui-tab-item" href="Discover.html">
<span class="mui-icon mui-icon-search"></span>
<span class="mui-tab-label">发现</span>
</a>
<a id="myhref" class="mui-tab-item" href="my.html">
<span class="mui-icon iconfont icon-my"></span>
<span class="mui-tab-label">我的</span>
</a>
</nav>
<script src="js/mui.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<script type="text/javascript" src="js/CommonFunction.js"></script>
<script type="text/javascript" charset="utf-8">
//mui初始化
mui.init();
var subpages = ['index.html', 'Inspiration.html', "MyDecorate.html", 'Discover.html', 'my.html'];
var subpage_style = {
top: '46px',
bottom: '50px',
render: "always",
scrollIndicator: 'none',
scrollsToTop:true,
};
var aniShow = {};
//创建子页面,首个选项卡页面显示,其它均隐藏;
mui.plusReady(function() {
var self = plus.webview.currentWebview();
for (var i = 0; i < 5; i++) {
var temp = {};
var sub = plus.webview.create(subpages[i], subpages[i], subpage_style);
if (i > 0) {
sub.hide();
} else {
temp[subpages[i]] = "true";
mui.extend(aniShow, temp);
}
self.append(sub);
}
// if (!plus.webview.defauleHardwareAccelerated() && parseInt(plus.os.version) >= 5) {
// styles.hardwareAccelerated = true;
// }
setTimeout(function() {
plus.navigator.closeSplashscreen();
}, 1500);
});
//当前激活选项
var activeTab = subpages[0];
var title = document.getElementById("title");
//选项卡点击事件
mui('.mui-bar-tab').on('tap', 'a', function(e) {
var targetTab = this.getAttribute('href');
if (targetTab == activeTab) {
return;
}
//更换标题
//title.innerHTML = this.querySelector('.mui-tab-label').innerHTML;
if (this.querySelector('.mui-tab-label').innerHTML == "首页")
title.innerHTML = "我来装";
else
title.innerHTML = this.querySelector('.mui-tab-label').innerHTML;
//显示目标选项卡
if (mui.os.ios || aniShow[targetTab]) {
plus.webview.show(targetTab);
} else {
var temp = {};
temp[targetTab] = "true";
mui.extend(aniShow, temp);
plus.webview.show(targetTab, "fade-in", 100);
}
//隐藏当前;
plus.webview.hide(activeTab);
//更改当前活跃的选项卡
activeTab = targetTab;
});
//自定义事件,模拟点击“首页选项卡”
document.addEventListener('gohome', function() {
var defaultTab = document.getElementById("defaultTab");
//模拟首页点击
mui.trigger(defaultTab, 'tap');
//切换选项卡高亮
var current = document.querySelector(".mui-bar-tab>.mui-tab-item.mui-active");
if (defaultTab !== current) {
current.classList.remove('mui-active');
defaultTab.classList.add('mui-active');
}
});
</script>
</body>
7 个回复
chender - 与人为善
是第一次打开某个tab的时候会闪,还是每次都闪
then0718 (作者)
就是 感觉webview会回收页面 然后会重新渲染 几乎是每次都会
chender - 与人为善
点击切换的时候没有重新加载页面吧,只是做的show和hide吧
我这边没有出现这样的问题
你是什么手机,系统版本是多少
then0718 (作者)
MX4 系统版本是4.4.2
2015-11-19 16:05
DCloud_UNI_CHB
上传一个可重现问题的简单示例demo吧;
泥鳅
关闭硬件加速试试
then0718 (作者)
效果不明显呢
2015-11-19 16:07
then0718 (作者)
以下就是主页的代码
<body>
<header class="mui-bar mui-bar-nav" style="height: 46px;">
<a id="locationimg" class="mui-icon mui-icon-location " style="color: gray;font-size: 19px;line-height: 25px;">
</a>
<label style="font-size: 14px;">成都</label>
<h1 id="title" class="mui-title" style="font-size: 22px;line-height: 50px;">首页</h1>
// if (!plus.webview.defauleHardwareAccelerated() && parseInt(plus.os.version) >= 5) {
// styles.hardwareAccelerated = true;
// }
setTimeout(function() {
plus.navigator.closeSplashscreen();
}, 1500);
});
//当前激活选项
var activeTab = subpages[0];
var title = document.getElementById("title");
//选项卡点击事件
mui('.mui-bar-tab').on('tap', 'a', function(e) {
var targetTab = this.getAttribute('href');
if (targetTab == activeTab) {
return;
}
//更换标题
//title.innerHTML = this.querySelector('.mui-tab-label').innerHTML;
if (this.querySelector('.mui-tab-label').innerHTML == "首页")
title.innerHTML = "我来装";
else
title.innerHTML = this.querySelector('.mui-tab-label').innerHTML;
//显示目标选项卡
if (mui.os.ios || aniShow[targetTab]) {
plus.webview.show(targetTab);
} else {
var temp = {};
temp[targetTab] = "true";
mui.extend(aniShow, temp);
plus.webview.show(targetTab, "fade-in", 100);
}
//隐藏当前;
plus.webview.hide(activeTab);
//更改当前活跃的选项卡
activeTab = targetTab;
});
//自定义事件,模拟点击“首页选项卡”
document.addEventListener('gohome', function() {
var defaultTab = document.getElementById("defaultTab");
//模拟首页点击
mui.trigger(defaultTab, 'tap');
//切换选项卡高亮
var current = document.querySelector(".mui-bar-tab>.mui-tab-item.mui-active");
if (defaultTab !== current) {
current.classList.remove('mui-active');
defaultTab.classList.add('mui-active');
}
});
</script>
</body>
5***@qq.com
这是由于mui.min.css中设置了icon的透明度.mui-bar .mui-icon:active{opacity:.3},改成100即可:.mui-bar .mui-icon:active{opacity:100}
培培弟
改了不生效
2018-08-15 16:03