index-menu.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Hello MUI</title>
  6. <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
  7. <meta name="apple-mobile-web-app-capable" content="yes">
  8. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  9. <link rel="stylesheet" href="css/mui.min.css">
  10. <style type="text/css">
  11. body,
  12. .mui-content {
  13. background-color: #333;
  14. color: #fff;
  15. }
  16. .title {
  17. margin: 35px 15px 10px;
  18. }
  19. .title+.content {
  20. margin: 10px 15px 35px;
  21. color: #bbb;
  22. text-indent: 1em;
  23. font-size: 14px;
  24. line-height: 24px;
  25. }
  26. .mui-table-view {
  27. margin-bottom: 35px;
  28. }
  29. </style>
  30. </head>
  31. <body>
  32. <div class="mui-content">
  33. <div class="title">侧滑导航</div>
  34. <div class="content">
  35. 这是首页侧滑导航示例,你可以在这里放置任何内容;<span style="display: none;">关闭侧滑菜单有多种方式: 1.点击本侧滑菜单页之外的任意位置; 2.点击如下红色按钮
  36. <span id="android-only">;3.Android手机按back键;4.Android手机按menu键。
  37. </span></span>
  38. <p style="margin: 10px 15px;">
  39. <button id="close-btn" type="button" class="mui-btn mui-btn-danger mui-btn-block" style="padding: 5px 20px;">关闭侧滑菜单</button>
  40. </p>
  41. </div>
  42. <div class="title" style="margin-bottom: 25px;">mui典型控件</div>
  43. <ul class="mui-table-view mui-table-view-chevron mui-table-view-inverted" style="color: #ddd;">
  44. <li class="mui-table-view-cell">
  45. <a class="mui-navigate-right" href="examples/pullrefresh_main.html">
  46. 下拉刷新
  47. </a>
  48. </li>
  49. <li class="mui-table-view-cell">
  50. <a class="mui-navigate-right" href="examples/offcanvas-drag-left.html">
  51. 侧滑导航
  52. </a>
  53. </li>
  54. <li class="mui-table-view-cell">
  55. <a class="mui-navigate-right" data-title-type="native" href="examples/switches.html">
  56. 开关控件
  57. </a>
  58. </li>
  59. <li class="mui-table-view-cell">
  60. <a class="mui-navigate-right" data-title-type="native" href="examples/tableviews-with-swipe.html">
  61. 列表左滑菜单
  62. </a>
  63. </li>
  64. <li class="mui-table-view-cell">
  65. <a class="mui-navigate-right" href="examples/tab-with-viewpagerindicator.html">
  66. 可拖动式选项卡
  67. </a>
  68. </li>
  69. </ul>
  70. </div>
  71. <script src="js/mui.min.js"></script>
  72. <script type="text/javascript" charset="utf-8">
  73. var aniShow = "slide-in-right";
  74. //关于backbutton和menubutton两个按键的说明,在iOS平台不存在,故需隐藏
  75. if(!mui.os.android) {
  76. var span = document.getElementById("android-only")
  77. if(span) {
  78. span.style.display = "none";
  79. }
  80. }
  81. var subWebview = null,
  82. template = null,
  83. index = null;
  84. mui.plusReady(function() {
  85. //获得主页面webview引用;
  86. index = plus.webview.currentWebview().opener();
  87. var _self = plus.webview.currentWebview();
  88. _self.drag({
  89. direction: "left",
  90. moveMode: "followFinger"
  91. }, {
  92. view: index,
  93. moveMode: "follow"
  94. }, function(e) {});
  95. })
  96. mui('.mui-table-view').on('tap', 'a', function() {
  97. var id = this.getAttribute("href");
  98. var type = this.getAttribute("open-type");
  99. var href = this.href;
  100. var webview_style = {
  101. popGesture: "close",
  102. statusbar : {
  103. background: "#f7f7f7"
  104. }
  105. }
  106. var extras = {};
  107. var titleType = this.getAttribute("data-title-type");
  108. if(titleType == "native") {
  109. if(!~id.indexOf('pullrefresh.html')) {
  110. webview_style.bounce = "vertical";
  111. }
  112. var webview = plus.webview.create(href, id, webview_style);
  113. var view = new plus.nativeObj.View("title", {
  114. top: 0,
  115. height: "44px",
  116. width: "100%",
  117. dock: "top",
  118. position: "dock"
  119. });
  120. view.drawRect("#f7f7f7"); //绘制背景色
  121. view.drawRect("#cccccc", {
  122. top: "43px",
  123. left: "0px"
  124. }); //绘制底部边线
  125. var bitmap = new plus.nativeObj.Bitmap("back");
  126. bitmap.loadBase64Data("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAb1BMVEUAAAAAev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8Aev8AAACubimgAAAAI3RSTlMAGfUTGfQTGPMSGPIYGhgaGBsXGxcbFxwXHBccFhwWHRYdHWufDPQAAAABYktHRACIBR1IAAAAB3RJTUUH4QETEBwooeTlkQAAAJVJREFUSMft1EkSgkAQRNFGUXFWHBDBibr/HTUwD5B/48Ig1y+io7u6MqUhf5hsNEY+j5hMgZ/FJ8Xc9ovos3T96utjbfqN/Nb0O/m96Uv5g+mP8ifTn+Ur01/ka9Nf5RvTt/I309/lH6Z/yr9Mn+Q71/MT8B34K/E58Enzv8R/K98HvnF8p3lr8F7izce7lbf3kJ/lDQp9HdBhgg3PAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE3LTAxLTE5VDE2OjI4OjQwKzA4OjAwpTDFwQAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxNy0wMS0xOVQxNjoyODo0MCswODowMNRtfX0AAAAASUVORK5CYII=");
  127. view.drawBitmap(bitmap, {}, {
  128. top: "10px",
  129. left: "10px",
  130. width: "24px",
  131. height: "24px"
  132. });
  133. view.drawText(this.innerText.trim(), {}, {
  134. size: "17px",
  135. weight: "normal"
  136. });
  137. view.setTouchEventRect({
  138. top: "0px",
  139. left: "0px",
  140. width: "44px",
  141. height: "100%"
  142. });
  143. view.interceptTouchEvent(true);
  144. view.addEventListener("click", function(e) {
  145. webview.evalJS("mui.back();");
  146. }, false);
  147. webview.append(view);
  148. webview.addEventListener("loaded", function() {
  149. webview.show(aniShow, 300, null, extras);
  150. })
  151. } else {
  152. //侧滑菜单需动态控制一下zindex值;
  153. if(~id.indexOf('offcanvas-')) {
  154. webview_style.zindex = 9998;
  155. webview_style.popGesture = ~id.indexOf('offcanvas-with-right') ? "close" : "none";
  156. }
  157. var webview = plus.webview.create(this.href, id, webview_style, extras);
  158. webview.addEventListener("loaded", function() {
  159. webview.show(aniShow, 300);
  160. });
  161. }
  162. });
  163. /**
  164. * 关闭侧滑菜单
  165. */
  166. function close() {
  167. mui.fire(mui.currentWebview.opener(), "menu:close");
  168. }
  169. //点击“关闭侧滑菜单”按钮处理逻辑
  170. document.getElementById("close-btn").addEventListener("tap", close);
  171. mui.init({
  172. swipeBack: false,
  173. keyEventBind: {
  174. backbutton: false //关闭back按键监听
  175. }
  176. });
  177. </script>
  178. </body>
  179. </html>