小程序 下拉選擇框


  <!-- 下拉框 -->
    <view class='select_box'>
      <view class='select' catchtap='selectTap'>
        <text class='select_text'>{{selectData[index]}}</text>
        <image class='words_img' src='../../images/dv.png'></image>
        <image class='select_img {{show&&"select_img_rotate"}}' src='/image/gobottom.png'></image>
      </view>
      <view class='option_box' style='height:{{show?(selectData.length>5?300:selectData.length*60):0}}rpx;'>
        <text class='option' style='{{index==selectData.length-1&&"border:0;"}}' wx:for='{{selectData}}' wx:key='this' data-index='{{index}}' catchtap='optionTap'>{{item}}</text>
      </view>
    </view>
data{
  show: false, //控制下拉列表的顯示隱藏,false隱藏、true顯示
    selectData: ['消費賬戶', '平台返利賬戶', '微信錢包'], //下拉列表的數據
    index: 0, //選擇的下拉列 表下標,
}

  // 點擊下拉顯示框
  selectTap() {
    this.setData({
      show: !this.data.show,
    });
  },
  // 點擊下拉列表
  optionTap(e) {
    let Index = e.currentTarget.dataset.index; //獲取點擊的下拉列表的下標
    this.setData({
      index: Index,
      show: !this.data.show
    });
  },
.select_box {
  background: #fff;
  width: 620rpx;
  margin: 0 auto;
  margin-top: 40rpx;
  height: 86rpx;
  line-height: 86rpx;
  text-align: left;
  position: relative;
}

.select {
  box-sizing: border-box;
  width: 100%;
  height: 86rpx;
  border: 1px solid #efefef;
  border-radius: 8rpx;
  display: flex;
  align-items: center;
  padding: 0 20rpx;
}

.select_text {
  font-size: 28rpx;
  flex: 1;
  color: rgb(102, 102, 102);
  line-height: 86rpx;
  height: 86rpx;
}

.select_img {
  width: 40rpx;
  height: 40rpx;
  display: block;
  transition: transform 0.3s;
}

.select_img_rotate {
  transform: rotate(180deg);
}

.option_box {
  position: absolute;
  top: 86rpx;
  width: 100%;
  border: 1px solid #efefef;
  box-sizing: border-box;
  height: 0;
  overflow-y: auto;
  border-top: 0;
  background: #fff;
  transition: height 0.3s;
}

.option {
  display: block;
  line-height: 40rpx;
  font-size: 28rpx;
  border-bottom: 1px solid #efefef;
  padding: 10rpx;
  color: rgb(102, 102, 102);
  font-size: 28rpx;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM