当前位置:首页 > 小程序 > 正文内容

小程序列表展开收起功能

tigon4年前 (2021-06-17)小程序2510

  1. index.wxml
  2. <block wx:for-items="{{list}}" wx:key="{{item.id}}">
  3. <view class="kind-list-item">
  4. <view id="{{item.id}}" class="kind-list-item-hd {{item.open ? 'kind-list-item-hd-show' : ''}}" bindtap="kindToggle">
  5. <view class="kind-list-text">{{item.name}}</view>
  6. </view>
  7. <view class="kind-list-item-bd {{item.open ? 'kind-list-item-bd-show' : ''}}">
  8. <view class="navigator-box {{item.open ? 'navigator-box-show' : ''}}">
  9. <block wx:for-items="{{item.pages}}" wx:for-item="page" wx:key="*item">
  10. <navigator url="pages/{{page}}/{{page}}" class="navigator">
  11. <view class="navigator-text">{{page}}</view>
  12. <!-- icon -->
  13. <view class="navigator-arrow"></view>
  14. </navigator>
  15. </block>
  16. </view>
  17. </view>
  18. </view>
  19. </block>
  20. index.css
  21. .navigator-box {
  22. opacity: 0;
  23. position: relative;
  24. background-color: #fff;
  25. line-height: 1.41176471;
  26. font-size: 34rpx;
  27. transform: translateY(-50%);
  28. transition: 0.3s;
  29. }
  30. .navigator-box-show {
  31. opacity: 1;
  32. transform: translateY(0);
  33. }
  34. .navigator {
  35. padding: 20rpx 30rpx;
  36. position: relative;
  37. display: flex;
  38. align-items: center;
  39. }
  40. .navigator:before {
  41. content: " ";
  42. position: absolute;
  43. left: 30rpx;
  44. top: 0;
  45. right: 30rpx;
  46. height: 1px;
  47. border-top: 1rpx solid #d8d8d8;
  48. color: #d8d8d8;
  49. }
  50. .navigator:first-child:before {
  51. display: none;
  52. }
  53. .navigator-text {
  54. flex: 1;
  55. }
  56. .navigator-arrow {
  57. padding-right: 26rpx;
  58. position: relative;
  59. }
  60. .navigator-arrow:after {
  61. content: " ";
  62. display: inline-block;
  63. height: 18rpx;
  64. width: 18rpx;
  65. border-width: 2rpx 2rpx 0 0;
  66. border-color: #888;
  67. border-style: solid;
  68. transform: matrix(0.71, 0.71, -0.71, 0.71, 0, 0);
  69. position: absolute;
  70. top: 50%;
  71. margin-top: -8rpx;
  72. right: 28rpx;
  73. }
  74. .kind-list-item {
  75. margin: 20rpx 0;
  76. background-color: #fff;
  77. border-radius: 4rpx;
  78. overflow: hidden;
  79. border-bottom: 1px dashed #888;
  80. }
  81. .kind-list-item:first-child {
  82. margin-top: 0;
  83. }
  84. .kind-list-text {
  85. flex: 1;
  86. }
  87. .kind-list-img {
  88. width: 60rpx;
  89. height: 60rpx;
  90. }
  91. .kind-list-item-hd {
  92. padding: 30rpx;
  93. display: flex;
  94. align-items: center;
  95. transition: opacity 0.3s;
  96. }
  97. .kind-list-item-hd-show {
  98. opacity: 0.2;
  99. }
  100. .kind-list-item-bd {
  101. height: 0;
  102. overflow: hidden;
  103. }
  104. .kind-list-item-bd-show {
  105. height: auto;
  106. }
  107. index.js
  108. Page({
  109. data: {
  110. list: [{
  111. id: 'view',
  112. name: '视图容器',
  113. open: false,
  114. pages: ['view', 'scroll-view', 'swiper', 'movable-view', 'cover-view']
  115. }, {
  116. id: 'content',
  117. name: '基础内容',
  118. open: false,
  119. pages: ['text', 'icon', 'progress', 'rich-text']
  120. }, {
  121. id: 'form',
  122. name: '表单组件',
  123. open: false,
  124. pages: ['button', 'checkbox', 'form', 'input', 'label', 'picker', 'picker-view', 'radio', 'slider', 'switch', 'textarea']
  125. }, {
  126. id: 'nav',
  127. name: '导航',
  128. open: false,
  129. pages: ['navigator']
  130. }, {
  131. id: 'media',
  132. name: '媒体组件',
  133. open: false,
  134. pages: ['image', 'audio', 'video', 'camera']
  135. }, {
  136. id: 'map',
  137. name: '地图',
  138. pages: ['map']
  139. }, {
  140. id: 'canvas',
  141. name: '画布',
  142. pages: ['canvas']
  143. }, {
  144. id: 'open',
  145. name: '开放能力',
  146. pages: ['ad', 'open-data', 'web-view']
  147. }]
  148. },
  149. /**
  150. * 收缩核心代码
  151. */
  152. kindToggle(e) {
  153. const id = e.currentTarget.id
  154. const list = this.data.list
  155. for (let i = 0, len = list.length; i < len; ++i) {
  156. if (list[i].id === id) {
  157. list[i].open = !list[i].open
  158. } else {
  159. list[i].open = false
  160. }
  161. }
  162. /**
  163. * key和value名称一样时,可以省略
  164. *
  165. * list:list=>list
  166. */
  167. this.setData({
  168. list
  169. })
  170. }
  171. })

版权声明:本文由Web学习之路发布,如需转载请注明出处。

本文链接:https://webge.net/?id=123

“小程序列表展开收起功能” 的相关文章

小程序-- wx.switchTab({url}) 跳转页面

wx.switchTab({url}) 传页面page地址 注意,页面会刷新,那下面导航如何选中呢? 1,在app.js里定义全局变量 globalData: { selected: 0, }, 2,每个页面引入全局变量 getApp().globalData.se...

小程序自定义下拉刷新

<scroll-view style='height:100%' scroll-y='{{!isindrag}}' bindscroll='scorll'> <view class='column' bindtouc...

小程序页面开启下拉刷新不回弹问题

onPullDownRefresh: function () { // 停止下拉动作 wx.stopPullDownRefresh(); //添加这句就可以了 if(this.data.searchContent){ this.setSearchListDataFn(th...

小程序 a到b到c ,从c直接回到a

1A页面跳转到B wx.navigateTo({ url: `/pages/signUp/A` }) 2,B页面到C wx.navigateTo({ url: `/pages/signUp/C` }) 从c加到A页面 在c页面写 onUnload: fun...

小程序接地图

小程序接地图

longitude latitude是中心经纬度markers 是所有打点的经纬度,微信地图也是包了高德地图 <map wx:if="{{mapShow}}" class="map" id="map" scale="...