小程序scroll-view滑动标签

跟風遠走 提交于 2020-02-25 19:35:45

在这里插入图片描述

  <scroll-view scroll-x="true" class="tag_scroll">
    <view class="label_nav" style="width:{{tagWidth}}">
      <view wx:for="{{tabitem}}" wx:key="index" class="item-text {{tabIndex===index?'activity':''}}" bindtap="setTab" data-index="{{index}}" data-id="{{item.id}}">{{item.title}}</view>
    </view>
  </scroll-view>
.tag_scroll {
  width: 750rpx;
  height: 90rpx;
  display: block;
}
.label_nav {
  width: 750rpx;
  height: 88rpx;
  background-color: #fff;
  border-bottom: 1px solid #eee;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  color: #333;
}
.item-text {
  display: inline-block;
  box-sizing: border-box;
  flex-shrink: 0;
  padding: 0 26rpx;
  height: 88rpx;
  font-size: 30rpx;
  line-height: 88rpx;
}

.item-text.activity {
  border-bottom: 2px solid #0fc191;
  color: #0fc191;
}

    tabitem: [{
        id: 1,
        title: "橘子"
      },
      {
        id: 2,
        title: "菠萝"
      },
      {
        id: 3,
        title: "香蕉"
      },
      {
        id: 4,
        title: "西瓜"
      },
      {
        id: 5,
        title: "火龙果"
      },
      {
        id: 6,
        title: "水蜜桃"
      },
      {
        id: 7,
        title: "水蜜桃"
      },
      {
        id: 8,
        title: "水蜜桃"
      }
    ],
    tabIndex: 0


  setTab: function(e) {
    console.log(e.currentTarget.dataset.id)
    this.setData({
      tabIndex: e.currentTarget.dataset.index,
    })
  },
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!