小程式實例:小程式實現折疊式選單的效果(附程式碼)

不言
發布: 2018-08-10 15:59:11
原創
4397 人瀏覽過

這篇文章帶給大家的內容是關於小程式實例:小程式實現折疊菜單的效果(附程式碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有幫助。

通常,選單都有一級選單二級、三級選單之分,我們知道前端js的dom操作可以很好的控制二級選單的顯示與隱藏,當然今天我就不介紹web端的選單折疊效果。我今天呢,是來學習學習小程式中該如何實現點擊一級選單顯示/隱藏二級選單,並且在點擊一個選單顯示之外,要實現其他選單隱藏。

實現效果如下:

程式碼如下:

   .wxml檔案

<view class="cells">
    <view class="item"  wx:for="{{List}}" wx:for-index="idx" wx:for-item="item" wx:key="idx">
        <view bindtap="isOpen" class="cdn" data-index="{{item.id}}">
            <view>
                <image class="img" src="{{item.iamges}}" mode="aspectFill"/><text class="content">{{item.cont}}</text>
            </view>
            <view>
                <text class="discount">{{item.discount}}</text><image class="icon_img" src="{{item.hidden ? &#39;/assets/icon_down2x.png&#39; : &#39;/assets/icon_up2x.png&#39;}}" mode="aspectFill"/>
            </view>
        </view>
        <view hidden="{{item.hiddena}}"  class="hidden">
            <block wx:for="{{item.invalidActivty}}"  wx:for-index="index" wx:for-item="items" wx:key="index">
                <view class="buys">
                    <view class="v1 ">
                        <navigator><text class="new-price">{{items.price}}</text><text class="oldPrice">{{items.oldPrice}}</text></navigator>
                        <navigator><text class="buy">{{items.validType}}</text><text style="font-size: 24rpx;margin-left: 20rpx;color: #6C6C6C">{{items.validTime}}</text></navigator>
                    </view>
                    <view  class="shopping">
                        <text>购买</text>
                    </view>
                </view>
            </block>
        </view>
    </view>
</view>
登入後複製

# .wxss檔案如下:

page{
    background: #fff;
}
.swiper-img{
    width: 750rpx;
    height: 300rpx;
}
.cells .item .cdn{
    position: relative;
    box-sizing:border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20rpx 30rpx;
    /*border-bottom: 1rpx solid #f0f0f0;*/
    background-color: #fff;
    font-size: 32rpx;
}
.cells .item .cdn::after{
    content:&#39;&#39;;position:absolute;top:0;left:0;width:200%;height:200%;-webkit-transform:scale(.5);transform:scale(.5);-webkit-transform-origin:0 0;transform-origin:0 0;pointer-events:none;box-sizing:border-box;border-bottom:0 solid #f0f0f0;border-width:1px
}

.img{
    height: 44rpx;
    width: 44rpx;
    vertical-align: middle;
    display: inline-block;
    line-height: 82rpx;
}

.icon_img{
    height:12rpx;
    width:20rpx;
}



.content{
    margin-left: 15rpx;
    line-height: 82rpx;
    vertical-align: middle;
}

.discount{
    line-height: 82rpx;
    vertical-align: middle;
    color:orange;
    box-sizing: border-box;
    padding-right: 20rpx;
}


.video-item{
    display: flex;
    flex-direction: column;
}
.buys{
    width:750rpx;
    height: 141.6rpx;
    position: relative;
    box-sizing: border-box;
    padding: 20rpx 30rpx;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    background-color:#FAFAFA;
}
.buys::after {
    content:&#39;&#39;;position:absolute;top:0;left:0;width:200%;height:200%;-webkit-transform:scale(.5);transform:scale(.5);-webkit-transform-origin:0 0;transform-origin:0 0;pointer-events:none;box-sizing:border-box;
    border-bottom:0 solid #DCDCDC;border-width:1px;
}
.v1{
    width: 35%;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
}

.new-price{
    font-size: 32rpx;
    color: #3B3B3B;
}
.oldPrice{
    text-decoration:line-through;
    font-size: 24rpx;
    color: #B0B0B0;
    margin-left: 20rpx;
}
.buy{
    font-size: 24rpx;
    color: #2DAF73;
    text-align: center;
    width: 80rpx;
    height: 40rpx;
    line-height: 40rpx;
    display: inline-block;
    position: relative;
    box-sizing: border-box;
}
.buy::after{
    content:&#39;&#39;;position:absolute;top:0;left:0;width:200%;height:200%;-webkit-transform:scale(.5);transform:scale(.5);-webkit-transform-origin:0 0;transform-origin:0 0;pointer-events:none;box-sizing:border-box;border:0 solid #2DAF73;border-width:1px;border-radius:8rpx
}

.shopping{
    width: 128rpx;
    height: 56rpx;
    line-height: 56rpx;
    position: relative;
    box-sizing: border-box;
    font-size: 28rpx;
    color: #2DAF73;
    text-align: center;
}
.shopping::after{
    content:&#39;&#39;;position:absolute;top:0;left:0;width:200%;height:200%;-webkit-transform:scale(.5);transform:scale(.5);-webkit-transform-origin:0 0;transform-origin:0 0;pointer-events:none;box-sizing:border-box;border:0 solid #2DAF73;border-width:1px;border-radius:16rpx
}
登入後複製

.js檔案

data: {
    memberList:[
        {iamges:"/assets/logo_aiqiyi2x.png",
          cont:"爱奇艺影视会员",
          discount:"7.5折",
          hiddena:true,
          id:"0",
          invalidActivty:[
            {
              price:"2.98元",
              oldPrice:"3元",
              validType:"周卡",
              validTime:&#39;7天有效&#39;
            },
            {
                price:"18.98元",
                oldPrice:"25元",
                validType:"月卡",
                validTime:&#39;30天有效&#39;
            },
          ]
        },
        {iamges:"/assets/logo_tengxun2x.png",
            cont:"腾讯视频会员",
            discount:"7折",
            hiddena:true,
            id:"1",
            invalidActivty:[
                {
                    price:"2.98元",
                    oldPrice:"3元",
                    validType:"周卡",
                    validTime:&#39;7天有效&#39;
                },
                {
                    price:"18.98元",
                    oldPrice:"25元",
                    validType:"月卡",
                    validTime:&#39;30天有效&#39;
                },
            ]
        },
        {iamges:"/assets/logo_youku2x.png",
            cont:"优酷视频黄金会员",
            discount:"8折",
            hiddena:true,
            id:"2",
            invalidActivty:[
                {
                    price:"2.98元",
                    oldPrice:"3元",
                    validType:"周卡",
                    validTime:&#39;7天有效&#39;
                },
                {
                    price:"18.98元",
                    oldPrice:"25元",
                    validType:"月卡",
                    validTime:&#39;30天有效&#39;
                },
            ]
        },
        {iamges:"/assets/logo_sohu2x.png",
            cont:"搜狐视频黄金会员",
            discount:"8折",
            hiddena:true,
            id:"3",
            invalidActivty:[
                {
                    price:"2.98元",
                    oldPrice:"3元",
                    validType:"周卡",
                    validTime:&#39;7天有效&#39;
                },
                {
                    price:"18.98元",
                    oldPrice:"25元",
                    validType:"月卡",
                    validTime:&#39;30天有效&#39;
                },
            ]
        },
    ]
  },
  isOpen:function(e){
      var that = this;
      var idx = e.currentTarget.dataset.index;
      console.log(idx);
      var memberList = that.data.MemberList;
      console.log(memberList);
      for (let i=0; i < memberList.length; i++){
          if (idx == i) {
              memberList[i].hidden=!memberList[i].hidden;
          } else {
             memberList[i].hidden=true;
          }
      }
      this.setData({MemberList:memberList});
      return true;
    },
登入後複製

 相關推薦:

小程式的開發:表單的驗證(程式碼)

小程式:實作點擊倒數計時的程式碼

#

以上是小程式實例:小程式實現折疊式選單的效果(附程式碼)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板