小程序tab + swiper 实现tab下轮播

<view class="course-advantage">

    <view class="list-active-tab course-types-tab">
      <view class="container">
        <view class="pull-right">
           <ul class="list-tabs clearfix">
              <li wx:for="{{ advantages }}" wx:key="{{ item.id }}" bindtap="change_tab" data-current="{{ index }}">
                {{ item.title }}
              </li>
           </ul>
        </view>
      </view>
    </view>
    
    <view class="list-active-content course-types-content">
      <view wx:for="{{ advantages }}" wx:key="{{ item.id }}">
        <view class="list-contents course-banner course-banner-l{{ index }} {{ current_tab == index ? 'c-active' : '' }}">
          <swiper autoplay="true" class="swiper-wrapper">
            <swiper-item wx:for="{{ util.getJsonImageSrc( item.images ) }}" wx:key="{{ item.id }}" class="swiper-slide banner">
              <image src="{{ util.getImageSrc( item ) }}" mode="widthFix" ></image>
            </swiper-item>
          </swiper>
        </view>
      </view>
    </view>
    
 </view>

我们需要在tab切换项上绑定事件,并获取到当前index

然后定义一个tab变量,判断是否等于index,相等则加上active,不相等则去掉active

 

'current_case_tab': 0,
change_tab: function (e) {
    var that = this
    var current_li = e.currentTarget.dataset.current
    that.setData({
      current_tab: current_li
    })
  },

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值