欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

微信小程序实现折叠展开效果

程序员文章站 2023-10-30 08:01:21
本文实例为大家分享了微信小程序实现折叠展开效果的具体代码,供大家参考,具体内容如下 wxml:

本文实例为大家分享了微信小程序实现折叠展开效果的具体代码,供大家参考,具体内容如下

wxml:

<view class="page">
<!-- 总数 -->
<view class="li" bindtap='changetoggle'>
<view class="left">总数</view>
<view class="right gray" >8</view>
</view>

<!--分类 -->
<view class="li" data-index="0" bindtap='changetoggle'>
<view class="left">类别1</view>
<view class="right">3 <text class="iconfont {{selectedflag[0]?'icon-shangjiantou':'icon-xiala'}}"> </text>
  </view>
 </view>
 <view hidden="{{!selectedflag[0]}}">
 <block wx:for="{{list01}}" wx:for-item="item" wx:for-index="index">
  <view class="li bg-gray">
  <view>展开1</view>
  </view>
 </block>
 </view>

 <view class="li" data-index="1" bindtap='changetoggle'>
 <view class="left">类别2</view>
 <view class="right">0
  <text class="iconfont {{selectedflag[1]?'icon-shangjiantou':'icon-xiala'}}"> </text>
 </view>
 </view>
 <view hidden="{{!selectedflag[1]}}">
 <block wx:for="{{list02}}" wx:for-item="item" wx:for-index="index">
  <view class="li bg-gray">
  <view>展开2</view>

  </view>
 </block>
 </view>

 <view class="li" data-index="2" bindtap='changetoggle'>
 <view class="left">类别3</view>
 <view class="right red">2
  <text class="iconfont {{selectedflag[2]?'icon-shangjiantou':'icon-xiala'}}"> </text>
 </view>
 </view>
 <view hidden="{{!selectedflag[2]}}">
 <block wx:for="{{list03}}" wx:for-item="item" wx:for-index="index">
  <view class="li bg-gray">
  <view>展开3</view>

  </view>
 </block>
 </view>


 <view class="li" data-index="3" bindtap='changetoggle'>
 <view class="left">类别4</view>
 <view class="right red">3
  <text class="iconfont {{selectedflag[3]?'icon-shangjiantou':'icon-xiala'}}"> </text>
 </view>
 </view>
 <view hidden="{{!selectedflag[3]}}">
 <block wx:for="{{list04}}" wx:for-item="item" wx:for-index="index">
  <view class="li bg-gray">
  <view>展开4</view>
  <view class="red">展开4右边</view>
  </view>
 </block>
 </view>

wxss:

/* 列表详情 */

.li {
 background-color: #fff;
 display: flex;
 justify-content: space-between;
 font-size: 34rpx;
 width: 92%;
 padding: 0 4%;
 height: 100rpx;
 line-height: 100rpx;
 border-bottom: 1rpx solid #f1f1f1;
}
.bg-gray{
 background-color: #ccc!important;
 border-bottom: 1rpx solid #fff!important;
}

.li .icon-xiala ,.icon-shangjiantou {
 color: #999;
 font-size: 28rpx;
}

.gray {
 color: #8e8e8e;
}

.red {
 color: #fe2e2e;
}

js:

page({
 data: {

 list01: [
  { item_id: 1 }, { item_id: 11 }, { item_id: 11 },
 ],
 list02: [

 ],
 list03: [
  { item_id: 11 }, { item_id: 11 }
 ],
 list04: [
  { item_id: 11 }, { item_id: 11 }, { item_id: 11 }
 ],

 // 展开折叠
 selectedflag: [false, false, false, false],

 },
 // 展开折叠选择 
 changetoggle:function(e){
 var index = e.currenttarget.dataset.index;
 if (this.data.selectedflag[index]){
  this.data.selectedflag[index] = false;
 }else{
  this.data.selectedflag[index] = true;
 }

 this.setdata({
  selectedflag: this.data.selectedflag
 })
 },

})

效果图,手风琴效果:

微信小程序实现折叠展开效果

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。