Skip to content

Commit 6d9a311

Browse files
committed
优化webview模式侧滑导航打开速度
1 parent ee023d2 commit 6d9a311

File tree

5 files changed

+49
-35
lines changed

5 files changed

+49
-35
lines changed

examples/hello-mui/examples/offcanvas-drag-left-plus-main.html

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,21 @@ <h1 class="mui-title">off canvas(侧滑导航)</h1>
100100
return true;
101101
}
102102
}
103-
//plusReady事件后,自动创建menu窗口;
103+
//plusReady事件后,自动创建menu窗口;
104104
mui.plusReady(function() {
105105
main = plus.webview.currentWebview();
106-
menu = mui.preload({
107-
id: 'offcanvas-drag-left-plus-menu',
108-
url: 'offcanvas-drag-left-plus-menu.html',
109-
styles: {
110-
left: "30%",
111-
width: '70%',
112-
zindex: 9997
113-
}
114-
});
106+
//setTimeout的目的是等待窗体动画结束后,再执行create webview操作,避免资源竞争,导致窗口动画不流畅;
107+
setTimeout(function () {
108+
menu = mui.preload({
109+
id: 'offcanvas-drag-left-plus-menu',
110+
url: 'offcanvas-drag-left-plus-menu.html',
111+
styles: {
112+
left: "30%",
113+
width: '70%',
114+
zindex: 9997
115+
}
116+
});
117+
},300);
115118
});
116119

117120
/*

examples/hello-mui/examples/offcanvas-drag-left-plus-menu.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@
7676
</div>
7777
<script src="../js/mui.min.js"></script>
7878
<script type="text/javascript" charset="utf-8">
79-
mui.init();
79+
//关闭back、menu按键监听,这样侧滑主界面会自动获得back和memu的按键事件,仅在主界面处理按键逻辑即可;
80+
mui.init({
81+
keyEventBind: {
82+
backbutton: false,
83+
menubutton: false
84+
}
85+
});
8086
var main = null;
8187
mui.plusReady(function () {
8288
main = plus.webview.currentWebview().opener();
@@ -90,8 +96,6 @@
9096
window.addEventListener("swiperight",closeMenu);
9197

9298
document.getElementById("close-btn").addEventListener('tap',closeMenu);
93-
mui.menu = closeMenu;
94-
mui.back = closeMenu;
9599
</script>
96100
</body>
97101

examples/hello-mui/examples/offcanvas-drag-left.html

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ <h1 class="mui-title">左滑导航</h1>
162162
//Android暂不支持整体移动动画
163163
if(!mui.os.android){
164164
document.getElementById("move-togger").classList.remove('mui-hidden');
165-
var spans = document.querySelectorAll('.android-only');
166-
for (var i=0,len=spans.length;i<len;i++) {
167-
spans[i].style.display = "none";
165+
var spans = document.querySelectorAll('.android-only');
166+
for (var i=0,len=spans.length;i<len;i++) {
167+
spans[i].style.display = "none";
168168
}
169169
}
170170

@@ -197,17 +197,15 @@ <h1 class="mui-title">左滑导航</h1>
197197
break;
198198
}
199199
offCanvasWrapper.offCanvas().refresh();
200-
offCanvasSide.classList.remove('mui-transitioning');
201-
offCanvasSide.setAttribute('style', '');
202200
}
203201
});
204202

205203

206-
document.getElementById('offCanvasShow').addEventListener('tap', function() {
207-
offCanvasWrapper.offCanvas('show');
208-
});
209-
document.getElementById('offCanvasHide').addEventListener('tap', function() {
210-
offCanvasWrapper.offCanvas('close');
204+
document.getElementById('offCanvasShow').addEventListener('tap', function() {
205+
offCanvasWrapper.offCanvas('show');
206+
});
207+
document.getElementById('offCanvasHide').addEventListener('tap', function() {
208+
offCanvasWrapper.offCanvas('close');
211209
});
212210
//主界面和侧滑菜单界面均支持区域滚动;
213211
mui('#offCanvasSideScroll').scroll();

examples/hello-mui/examples/offcanvas-drag-right-plus-main.html

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,23 @@ <h1 class="mui-title">off canvas(侧滑导航)</h1>
9898
return true;
9999
}
100100
}
101-
//plusReady事件后,自动创建menu窗口;
101+
//plusReady事件后,自动创建menu窗口;
102102
mui.plusReady(function() {
103103
main = plus.webview.currentWebview();
104-
//侧滑菜单默认隐藏,这样可以节省内存;
105-
menu = mui.preload({
106-
id: 'offcanvas-drag-right-plus-menu',
107-
url: 'offcanvas-drag-right-plus-menu.html',
108-
styles: {
109-
left: 0,
110-
width: '70%',
111-
zindex: 9997
112-
}
113-
});
104+
//setTimeout的目的是等待窗体动画结束后,再执行create webview操作,避免资源竞争,导致窗口动画不流畅;
105+
setTimeout(function () {
106+
//侧滑菜单默认隐藏,这样可以节省内存;
107+
menu = mui.preload({
108+
id: 'offcanvas-drag-right-plus-menu',
109+
url: 'offcanvas-drag-right-plus-menu.html',
110+
styles: {
111+
left: 0,
112+
width: '70%',
113+
zindex: 9997
114+
}
115+
});
116+
},300);
117+
114118
});
115119
/**
116120
* 显示菜单菜单

examples/hello-mui/examples/offcanvas-drag-right-plus-menu.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@
8787
</div>
8888
<script src="../js/mui.min.js"></script>
8989
<script type="text/javascript" charset="utf-8">
90-
mui.init();
90+
mui.init({
91+
keyEventBind: {
92+
backbutton: false,
93+
menubutton: false
94+
}
95+
});
9196
//获得侧滑主窗口webview对象
9297
var main = null;
9398
mui.plusReady(function () {

0 commit comments

Comments
 (0)