欢迎光临,了解微信小程序开发,就上易用通!

微信小程序下拉菜单效果

发布:2018-01-24 16:27浏览: 来源:网络 作者:tianshu

微信小程序下拉菜单效果(图1)

  1. //wcss  
  2. /**DropDownMenu**/  
  3. /*总菜单容器*/  
  4. .menu {  
  5.   display: block;  
  6.   height: 28px;  
  7.   position: relative;  
  8. }  
  9. /*一级菜单*/  
  10. .menu dt {  
  11.   font-size: 15px;  
  12.   float: left;  
  13.   /*hack*/  
  14.   width: 33%;  
  15.   height: 38px;  
  16.   border-right: 1px solid #d2d2d2;  
  17.   border-bottom: 1px solid #d2d2d2;  
  18.   text-align: center;  
  19.   background-color: #f4f4f4;  
  20.   color: #5a5a5a;  
  21.   line-height: 38px;  
  22.   z-index: 2;  
  23. }  
  24. /*二级菜单外部容器样式*/  
  25. .menu dd {  
  26.   position: absolute;  
  27.   width: 100%;  
  28.   margin-top: 40px;  
  29.   left: 0;  
  30.   z-index: -99;  
  31. }  
  32. /*二级菜单普通样式*/  
  33. .menu li {  
  34.   font-size: 14px;  
  35.   line-height: 34px;  
  36.   color: #575757;  
  37.   height: 34px;  
  38.   display: block;  
  39.   padding-left: 8px;  
  40.   background-color: #fff;  
  41.   border-bottom: 1px solid #dbdbdb;  
  42. }  
  43. /*二级菜单高亮样式*/  
  44. .menu li.highlight {  
  45.   background-color: #f4f4f4;  
  46.   color: #48c23d;  
  47. }  
  48. /* 显示与隐藏 */  
  49. .show {  
  50.   /*display: block;*/  
  51.   visibility: visible;  
  52. }  
  53. .hidden {  
  54.   /*display: none;*/  
  55.   visibility: hidden;  
  56. }  


 
    1. //wxml   
    2. <dl class="menu">  
    3.     <block wx:for="{{reportData}}" wx:key="idMenu" wx:for-item="menuItem" wx:for-index="idMenu">  
    4.       <dt data-index="{{idMenu}}" bindtap="tapMainMenu">{{menuItem.reportType}}</dt>  
    5.       <dd class="{{subMenuDisplay[idMenu]}}" animation="{{animationData[idMenu]}}">  
    6.         <ul wx:for="{{menuItem.chilItem}}" wx:key="chilItem.ID" wx:for-item="chilItem" wx:for-index="idChil">  
    7.           <li class="{{subMenuHighLight[idMenu][idChil]}}" bindtap="tapSubMenu" data-index="{{idMenu}}-{{idChil}}">{{chilItem.Name}}</li>  
    8.         </ul>  
    9.         <picker class="timePicker" mode="date" value="{{dateValue}}" bindchange="datePickerBindchange" start="1999-01-01" end="2999-12-12"> 时间:{{dateValue}}</picker>  
    10.       </dd>  
    11.     </block>  
    12. </dl>  




     
    1. //js  
    2. //数据源  
    3. var ReportDataSync = [  
    4.     {  
    5.         reportType: "日报1",  
    6.         chilItem: [  
    7.             { ID: 1, Name: "日报1", ReportUrl: "DailyReport.aspx", Type: 1 },  
    8.             { ID: 2, Name: "日报2", ReportUrl: "DailyReport.aspx", Type: 1 },  
    9.             { ID: 3, Name: "日报3", ReportUrl: "DailyReport.aspx", Type: 1   
    10.     },  
    11.     {  
    12.         reportType: "目录2",  
    13.         chilItem: [  
    14.             { ID: 1, Name: "目录1", ReportUrl: "DailyReport.aspx", Type: 2 },  
    15.             { ID: 2, Name: "目录2", ReportUrl: "DailyReport.aspx", Type: 2 },  
    16.             { ID: 3, Name: "目录3", ReportUrl: "DailyReport.aspx", Type: 2 },  
    17.             { ID: 4, Name: "目录4", ReportUrl: "DailyReport.aspx", Type: 2   
    18.     },  
    19.     {  
    20.         reportType: "月报3",  
    21.         chilItem: [  
    22.             { ID: 1, Name: "月报1", ReportUrl: "DailyReport.aspx", Type: 1 },  
    23.             { ID: 2, Name: "月报2", ReportUrl: "DailyReport.aspx", Type: 2   
    24.     }  
    25.   
    26. //定义字段  
    27. var initSubMenuDisplay = []   
    28. var initSubMenuHighLight = []  
    29. /// 初始化DropDownMenu  
    30. loadDropDownMenu()  
    31. that.setData({  
    32.     reportData: ReportDataSync,//菜单数据  
    33.     subMenuDisplay: initSubMenuDisplay, //一级  
    34.     subMenuHighLight: initSubMenuHighLight //二级  
    35. })  
    36. //一级菜单点击  
    37. tapMainMenu: function (e) {  
    38.     //获取当前一级菜单标识  
    39.     var index = parseInt(e.currentTarget.dataset.index);  
    40.     //改变显示状态  
    41.     for (var i = 0; i < initSubMenuDisplay.length; i++) {  
    42.         if (i == index) {  
    43.             if (this.data.subMenuDisplay[index == "show") {  
    44.                 initSubMenuDisplay[index = 'hidden'  
    45.             } else {  
    46.                 initSubMenuDisplay[index = 'show'  
    47.             }  
    48.         } else {  
    49.             initSubMenuDisplay[i = 'hidden'  
    50.         }  
    51.     }  
    52.     this.setData({  
    53.         subMenuDisplay: initSubMenuDisplay  
    54.     })  
    55. },  
    56. //二级菜单点击  
    57. tapSubMenu: function (e) {  
    58.     //隐藏所有一级菜单  
    59.     //this.setData({  
    60.     //subMenuDisplay: initSubMenuDisplay()  
    61.     //});  
    62.     // 当前二级菜单的标识  
    63.     var indexArray = e.currentTarget.dataset.index.split('-');  
    64.      // 删除所在二级菜单样式  
    65.     for (var i = 0; i < initSubMenuHighLight.length; i++) {  
    66.         if (indexArray[0 == i) {  
    67.             for (var j = 0; j < initSubMenuHighLight[i].length; j++) {  
    68.                 initSubMenuHighLight[i][j = '';  
    69.             }  
    70.         }  
    71.     }  
    72.     //给当前二级菜单添加样式  
    73.     initSubMenuHighLight[indexArray[0]][indexArray[1 = 'highlight';  
    74.     //刷新样式  
    75.     this.setData({  
    76.         subMenuHighLight: initSubMenuHighLight  
    77.     });  
    78. }  
    79. /// <summary>  
    80. /// 初始化DropDownMenu  
    81. /// 1.一级目录 initSubMenuDisplay :['hidden']  
    82. /// 2.二级目录 initSubMenuHighLight :[['',''],['','','','']]]  
    83. /// </summary>  
    84. function loadDropDownMenu() {  
    85.     for (var i = 0; i < ReportDataSync.length; i++) {  
    86.         //一级目录  
    87.         initSubMenuDisplay.push('hidden')  
    88.         //二级目录  
    89.         var report = []  
    90.         for (var j = 0; j < ReportDataSync[i].chilItem.length; j++) {  
    91.             report.push([''])  
    92.         }  
    93.         initSubMenuHighLight.push(report)  
    94.     }  
    95. }  





免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。