小程序实现单选效果

实现点击小圆出现边框以及小勾
a
布局

  <view class="subtitleColor">
    <view class="item" wx:for='{{FontColorArr}}' data-index="{{item.index}}" bindtap="setFontColor" wx:key='index'>
      <view class="box {{currentFontTab==item.index?'boxBorder':''}}" style="background-color:{{item.color}}"></view>
      <image wx:if="{{currentFontTab==item.index}}" class="img" src="../../images/img1.png" />
    </view>
  </view>

样式less

.subtitleColor{

        .item{
            display: inline-block;
            position: relative;
            // border: 1px solid red;
            margin-left: 20rpx;
    
            .box{
                box-sizing:border-box;
                width: 82rpx;
                height: 82rpx;
                background-color: #ffff;
                border-radius: 50%;
                
            }
            .boxBorder{
                border: 5rpx solid #91B3F7;
            }
            .img{
                position: absolute;
                bottom: 8rpx;
                right: 8rpx;
                width: 26rpx;
                height: 26rpx;
            }
        }
    }

js

data:{
    FontColorArr: [
      { index: 0, color: '#FFFFFF' },
      { index: 1, color: "#E05B33" },
      { index: 2, color: "#E09833" },
      { index: 3, color: "#F3D21A" },
      { index: 4, color: "#6AC614" },
      { index: 5, color: "#14C685" },
      { index: 6, color: "#1351C5" }
    ],
    currentFontTab: 0,
}

//方法
  setFontColor: function (e) {
    let index = e.currentTarget.dataset.index;
    console.log(index)
    this.setData({
      currentFontTab: index
    })
  },
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页