Hbuilder Development App Tutorial 09-slide-by menu
Source: Internet
Author: User
<span id="Label3"></p><p><p></p></p>Slide Menu function<br><p><p>The previous section describes the list page, which tells a more common feature, the slide-by menu,</p></p><p><p>The Plan menu in this app is used to record what has been DONE.</p></p>Implementation method<p><p>Using Hbuilder to achieve similar side-by-side menu such as native app functionality, generally there are two ways to implement, see Here.</p></p><p><p>The first is the realization of webview, the second is the Div simulation,</p></p><p><p>The difference between the two is that the DIV implements a simple answer, but the occasional effect is not very good,</p></p><p><p>WebView implementation is slightly more complex, the page value is also complex, but the effect is good, generally recommended WebView implementation way.</p></p><p><p><br></p></p>Index.html Code<p><p>You need to add the following code in the Index.js</p></p><pre class="brush:js;toolbar:false"><pre class="brush:js;toolbar:false">var main = Null;var ShowMenu = False;var Menu = Null;var Add = Null;var Detail = Null;//all methods are put here Mui.plusready (function () { //initialize database initdb (); Slide-slip menu main = qiao.h.indexpage (); var menuoptions = qiao.h.page (' menu ', { styles: { left:0, width: ' 70% ', zindex:-1 } }); menu = Mui.preload (menuoptions); Qiao.on ('. mui-icon-bars ', ' tap ', opmenu); Main.addeventlistener (' maskclick ', opmenu); Mui.menu = opmenu; Exit mui.back = function () { if ($ ('. adda '). is (': hidden ')) { hideadd (); } else if (showmenu) { closemenu (); } else{ qiao.h.exit (); } };});</pre></pre>Get Main Page<p><p>Many times you need to get the main page on other pages, but the default main page is automatically loaded, that is, no ID is explicitly specified.</p></p><p><p>So ID how to get it, need to call a Nativejs method:<br></p></p><pre class="brush:js;toolbar:false"><pre class="brush:js;toolbar:false">Qiao.h.indexpage = function () { return plus.webview.getWebviewById (plus.runtime.appid);};</pre></pre>Pre-load Menu Page<p><p>There are several ways to say the open page, which loads the menu page in a preloaded way,</p></p>pop-up menu<p><p>You can add events individually from the menu icon in the Upper-right corner, or from the System's default menu key:</p></p><pre class="brush:js;toolbar:false"><pre class="brush:js;toolbar:false">Qiao.on ('. mui-icon-bars ', ' tap ', opmenu); mui.menu = opmenu;</pre></pre><p><p>Where Qiao.on is only the encapsulation of the JQ on Method.</p></p>Hide Menu<p><p>When you click the mask, or click System back, the System menu needs to hide the menu:</p></p><pre class="brush:js;toolbar:false"><pre class="brush:js;toolbar:false"> Main.addeventlistener (' maskclick ', opmenu); Exit mui.back = function () { if ($ ('. adda '). is (': hidden ')) { hideadd (); } else if (showmenu) { closemenu (); } else{ qiao.h.exit (); } };</pre></pre><p><p>Related methods</p></p><p><p>Lists methods for pop-up menus and hidden menus for other places to Invoke:</p></p><pre class="brush:js;toolbar:false"><pre class="brush:js;toolbar:false">Menufunction opmenu () { if (showmenu) { closemenu (); } else{ Openmenu (); }} function Openmenu () { if ($ ('. adda '). is (': visible ')) { menu.show (' None ', 0, function () { main.setstyle ({ mask: ' Rgba (0,0,0,0.4) ', left : ' 70% ', transition: { duration:150 } }); ShowMenu = true;} );} } function Closemenu () { main.setstyle ({ mask: ' None ', left : ' 0 ', transition: { duration:100 } }); ShowMenu = false; SetTimeout (function () { menu.hide (); }, 300);}</pre></pre><p><p>Combine a flag shoumenu to pop up or hide the menu.</p></p><p><p>Summarize</p></p><p><p>Here the index page menu related to finished,</p></p><p><p>mostly, 1. pre-load Menu page, 2. System menu, upper right corner menu, 3 System menu, system back, Click Mask Hide Menu.<br></p></p><p><p><br></p></p>list.html Right Slide popup menu<p><p>The above just defines some way to hide pop-up menus in index.html,</p></p><p><p>Regardless of the system menu button, the system background button, The mask is on the index page to listen,</p></p><p><p>The most common right-slide pop-up menu is not on the index page, because the list page takes up most of the homepage, so the Right-slip event is placed on the list Page.</p></p><pre class="brush:js;toolbar:false"><pre class="brush:js;toolbar:false">Right-swipe menu window.addeventlistener (' swiperight ', function () { qiao.h.indexpage (). evaljs ("opmenu ();"); });</pre></pre><p><p>Note here that the menu action method of the index is Called.</p></p><p><p>Page piece value and operation, a common method is to get the Page object and then call Evaljs.<br></p></p>Default Event<pre class="brush:js;toolbar:false"><pre class="brush:js;toolbar:false">Initialize Mui.init ({ keyeventbind: { backbutton:false, menubutton:false }, gestureconfig: { Longtap:true }});</pre></pre><p><p>Before I said Mui.init would initialize some default events,</p></p><p><p>Both buttons on the other pages are disabled because both the System menu button and the back button are monitored on the index page.</p></p><p><p><br></p></p>Review<p><p>At this point, the right-click menu function is complete,</p></p><p><p>1. Using the WebView method to achieve</p></p><p><p>The 2.index page listens to the System menu button and the System back button pops up the hidden slide menu</p></p><p><p>3.list page Disabled System Menu button, system Back button</p></p><p><p>4.index page click on the top right icon, click on the Mask pop-up hidden slide menu</p></p><p><p>5.list Page Right-slide Popup menu.</p></p><p><p><br></p></p>More Tutorials:<p><p>Hbuilder Development App Tutorial: HTTP://UIKOO9.COM/BOOK/DETAIL/3</p></p><p><p>More study Notes: Http://uikoo9.com/book</p></p> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced.</p></p> <p><p>Hbuilder Development App Tutorial 09-slide-by menu</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service