offcanvas-drag-down.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Hello MUI</title>
  6. <meta name="viewport" content="width=device-width, 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>
  11. html,
  12. body {
  13. min-height: 100%;
  14. background-color: #efeff4;
  15. }
  16. .animated {
  17. -webkit-animation-duration: 0.5s;
  18. animation-duration: 0.5s;
  19. -webkit-animation-fill-mode: both;
  20. animation-fill-mode: both;
  21. }
  22. @-webkit-keyframes bounceInDown {
  23. 0%, 60%, 75%, 90%, 100% {
  24. -webkit-transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
  25. transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
  26. }
  27. 0% {
  28. opacity: 0;
  29. -webkit-transform: translate3d(0, -100%, 0);
  30. transform: translate3d(0, -100%, 0);
  31. }
  32. 60% {
  33. opacity: 1;
  34. -webkit-transform: translate3d(0, 25px, 0);
  35. transform: translate3d(0, 25px, 0);
  36. }
  37. 75% {
  38. -webkit-transform: translate3d(0, -10px, 0);
  39. transform: translate3d(0, -10px, 0);
  40. }
  41. 90% {
  42. -webkit-transform: translate3d(0, 5px, 0);
  43. transform: translate3d(0, 5px, 0);
  44. }
  45. 100% {
  46. -webkit-transform: none;
  47. transform: none;
  48. }
  49. }
  50. @keyframes bounceInDown {
  51. 0%, 60%, 75%, 90%, 100% {
  52. -webkit-transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
  53. transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
  54. }
  55. 0% {
  56. opacity: 0;
  57. -webkit-transform: translate3d(0, -100%, 0);
  58. transform: translate3d(0, -100%, 0);
  59. }
  60. 60% {
  61. opacity: 1;
  62. -webkit-transform: translate3d(0, 25px, 0);
  63. transform: translate3d(0, 25px, 0);
  64. }
  65. 75% {
  66. -webkit-transform: translate3d(0, -10px, 0);
  67. transform: translate3d(0, -10px, 0);
  68. }
  69. 90% {
  70. -webkit-transform: translate3d(0, 5px, 0);
  71. transform: translate3d(0, 5px, 0);
  72. }
  73. 100% {
  74. -webkit-transform: none;
  75. transform: none;
  76. }
  77. }
  78. .bounce-in-down {
  79. -webkit-animation-name: bounceInDown;
  80. animation-name: bounceInDown;
  81. }
  82. @-webkit-keyframes fadeInDown {
  83. 0%, 60%, 75%, 90%, 100% {
  84. -webkit-transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
  85. transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
  86. }
  87. 0% {
  88. opacity: 0;
  89. -webkit-transform: translate3d(0, -100%, 0);
  90. transform: translate3d(0, -100%, 0);
  91. }
  92. 60% {
  93. opacity: 1;
  94. -webkit-transform: translate3d(0, 0px, 0);
  95. transform: translate3d(0, 0px, 0);
  96. }
  97. 75% {
  98. -webkit-transform: translate3d(0, 0px, 0);
  99. transform: translate3d(0, 0px, 0);
  100. }
  101. 90% {
  102. -webkit-transform: translate3d(0, 0px, 0);
  103. transform: translate3d(0, 0px, 0);
  104. }
  105. 100% {
  106. -webkit-transform: none;
  107. transform: none;
  108. }
  109. }
  110. @keyframes fadeInDown {
  111. 0%, 60%, 75%, 90%, 100% {
  112. -webkit-transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
  113. transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
  114. }
  115. 0% {
  116. opacity: 0;
  117. -webkit-transform: translate3d(0, -100%, 0);
  118. transform: translate3d(0, -100%, 0);
  119. }
  120. 60% {
  121. opacity: 1;
  122. -webkit-transform: translate3d(0, 0px, 0);
  123. transform: translate3d(0, 0px, 0);
  124. }
  125. 75% {
  126. -webkit-transform: translate3d(0, 0px, 0);
  127. transform: translate3d(0, 0px, 0);
  128. }
  129. 90% {
  130. -webkit-transform: translate3d(0, 0px, 0);
  131. transform: translate3d(0, 0px, 0);
  132. }
  133. 100% {
  134. -webkit-transform: none;
  135. transform: none;
  136. }
  137. }
  138. .fade-in-down {
  139. -webkit-animation-name: fadeInDown;
  140. animation-name: fadeInDown;
  141. }
  142. @-webkit-keyframes bounceOutUp {
  143. 20% {
  144. -webkit-transform: translate3d(0, -10px, 0);
  145. transform: translate3d(0, -10px, 0);
  146. }
  147. 40%,
  148. 45% {
  149. opacity: 1;
  150. -webkit-transform: translate3d(0, 20px, 0);
  151. transform: translate3d(0, 20px, 0);
  152. }
  153. 100% {
  154. opacity: 0;
  155. -webkit-transform: translate3d(0, -100%, 0);
  156. transform: translate3d(0, -100%, 0);
  157. }
  158. }
  159. @keyframes bounceOutUp {
  160. 20% {
  161. -webkit-transform: translate3d(0, -10px, 0);
  162. transform: translate3d(0, -10px, 0);
  163. }
  164. 40%,
  165. 45% {
  166. opacity: 1;
  167. -webkit-transform: translate3d(0, 20px, 0);
  168. transform: translate3d(0, 20px, 0);
  169. }
  170. 100% {
  171. opacity: 0;
  172. -webkit-transform: translate3d(0, -100%, 0);
  173. transform: translate3d(0, -100%, 0);
  174. }
  175. }
  176. .bounce-out-up {
  177. -webkit-animation-name: bounceOutUp;
  178. animation-name: bounceOutUp;
  179. }
  180. @-webkit-keyframes fadeOutUp {
  181. 20% {
  182. -webkit-transform: translate3d(0, 0px, 0);
  183. transform: translate3d(0, 0px, 0);
  184. }
  185. 40%,
  186. 45% {
  187. opacity: 1;
  188. -webkit-transform: translate3d(0, 0px, 0);
  189. transform: translate3d(0, 0px, 0);
  190. }
  191. 100% {
  192. opacity: 0;
  193. -webkit-transform: translate3d(0, -100%, 0);
  194. transform: translate3d(0, -100%, 0);
  195. }
  196. }
  197. @keyframes fadeOutUp {
  198. 20% {
  199. -webkit-transform: translate3d(0, 0px, 0);
  200. transform: translate3d(0, 0px, 0);
  201. }
  202. 40%,
  203. 45% {
  204. opacity: 1;
  205. -webkit-transform: translate3d(0, 0px, 0);
  206. transform: translate3d(0, 0px, 0);
  207. }
  208. 100% {
  209. opacity: 0;
  210. -webkit-transform: translate3d(0, -100%, 0);
  211. transform: translate3d(0, -100%, 0);
  212. }
  213. }
  214. .fade-out-up {
  215. -webkit-animation-name: fadeOutUp;
  216. animation-name: fadeOutUp;
  217. }
  218. .menu-open {
  219. height: 100%;
  220. width: 100%;
  221. }
  222. .menu-open .mui-scroll-wrapper {
  223. position: absolute;
  224. top: 48;
  225. bottom: 0;
  226. left: 0;
  227. z-index: 1;
  228. width: 100%;
  229. overflow: hidden;
  230. -webkit-backface-visibility: hidden;
  231. }
  232. .menu-backdrop {
  233. display: none;
  234. }
  235. .menu-open .menu-backdrop {
  236. position: fixed;
  237. top: 0;
  238. bottom: 0;
  239. height: 100%;
  240. width: 100%;
  241. display: block;
  242. z-index: 998;
  243. }
  244. .menu-wrapper {
  245. position: absolute;
  246. top: 48px;
  247. left: 0;
  248. right: 0;
  249. z-index: 999;
  250. text-align: center;
  251. background-color: #333;
  252. width: 100%;
  253. }
  254. .menu-wrapper.hidden {
  255. -webkit-transform: translate3d(0, -100%, 0);
  256. transform: translate3d(0, -100%, 0);
  257. z-index: -1;
  258. }
  259. .menu {
  260. width: 100%;
  261. }
  262. .menu .mui-table-view-inverted {
  263. color: gray;
  264. font-size: 19px;
  265. }
  266. .menu .mui-table-view-inverted .mui-table-view-cell:after {
  267. height: 2px;
  268. left: 0;
  269. right: 0;
  270. }
  271. .menu-wrapper.mui-active,
  272. .menu-wrapper.mui-active .menu {
  273. -webkit-transform: translate3d(0, 0, 0);
  274. transform: translate3d(0, 0, 0);
  275. }
  276. #info{
  277. padding: 20px 10px ;
  278. }
  279. </style>
  280. </head>
  281. <body>
  282. <header class="mui-bar mui-bar-nav">
  283. <a id="icon-menu" class="mui-action-menu mui-icon mui-icon-bars mui-pull-left"></a>
  284. <a class="mui-action-back mui-btn mui-btn-link mui-pull-right">关闭</a>
  285. <h1 class="mui-title">div模式下拉菜单</h1>
  286. </header>
  287. <div class="mui-content">
  288. <div class="mui-content-padded" >
  289. <p>这是div模式下沉菜单示例,主页面和菜单在一个HTML文件中,
  290. 当前页面为主界面,你可以在主界面放置任何内容;
  291. 打开侧滑菜单有多种方式: 1、点击页面左上角的
  292. <span class="mui-icon mui-icon-bars"></span> 图标;
  293. 2、通过JS API触发(例如点击如下蓝色按钮体验);
  294. <span class="android-only">3、Android手机按menu键;</span>
  295. </p>
  296. <p style="padding: 5px 20px;margin-bottom: 5px;">
  297. <button id="menu-btn" type="button" class="mui-btn mui-btn-primary mui-btn-block" style="padding: 10px;">
  298. 显示下拉菜单
  299. </button>
  300. </p>
  301. <div id="info"></div>
  302. </div>
  303. </div>
  304. <div id="menu-wrapper" class="menu-wrapper hidden">
  305. <div id="menu" class="menu">
  306. <ul class="mui-table-view mui-table-view-inverted">
  307. <li class="mui-table-view-cell">
  308. <a href="javascript:;">Item 1</a>
  309. </li>
  310. <li class="mui-table-view-cell">
  311. <a href="javascript:;">Item 2</a>
  312. </li>
  313. <li class="mui-table-view-cell">
  314. <a href="javascript:;">Item 3</a>
  315. </li>
  316. <li class="mui-table-view-cell">
  317. <a href="javascript:;">Item 4</a>
  318. </li>
  319. <li class="mui-table-view-cell">
  320. <a href="javascript:;">Item 5</a>
  321. </li>
  322. <li class="mui-table-view-cell">
  323. <a href="javascript:;">Item 6</a>
  324. </li>
  325. <li class="mui-table-view-cell">
  326. <a href="javascript:;">Item 7</a>
  327. </li>
  328. </ul>
  329. </div>
  330. </div>
  331. <div id="menu-backdrop" class="menu-backdrop"></div>
  332. <script src="../js/mui.min.js"></script>
  333. <script>
  334. mui.init({
  335. swipeBack:true //启用右滑关闭功能
  336. });
  337. var menuWrapper = document.getElementById("menu-wrapper");
  338. var menu = document.getElementById("menu");
  339. var menuWrapperClassList = menuWrapper.classList;
  340. var backdrop = document.getElementById("menu-backdrop");
  341. var info = document.getElementById("info");
  342. backdrop.addEventListener('tap', toggleMenu);
  343. document.getElementById("menu-btn").addEventListener('tap', toggleMenu);
  344. document.getElementById("icon-menu").addEventListener('tap',toggleMenu)
  345. //下沉菜单中的点击事件
  346. mui('#menu').on('tap', 'a', function() {
  347. toggleMenu();
  348. info.innerHTML = '你已选择:'+this.innerHTML;
  349. });
  350. var busying = false;
  351. function toggleMenu() {
  352. if (busying) {
  353. return;
  354. }
  355. busying = true;
  356. if (menuWrapperClassList.contains('mui-active')) {
  357. document.body.classList.remove('menu-open');
  358. menuWrapper.className = 'menu-wrapper fade-out-up animated';
  359. menu.className = 'menu bounce-out-up animated';
  360. setTimeout(function() {
  361. backdrop.style.opacity = 0;
  362. menuWrapper.classList.add('hidden');
  363. }, 500);
  364. } else {
  365. document.body.classList.add('menu-open');
  366. menuWrapper.className = 'menu-wrapper fade-in-down animated mui-active';
  367. menu.className = 'menu bounce-in-down animated';
  368. backdrop.style.opacity = 1;
  369. }
  370. setTimeout(function() {
  371. busying = false;
  372. }, 500);
  373. }
  374. </script>
  375. </body>
  376. </html>