小程序开发中如何利用Tab实现一个滚动选项卡-创新互联

这篇文章给大家介绍小程序开发中如何利用Tab实现一个滚动选项卡,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

成都创新互联公司基于成都重庆香港及美国等地区分布式IDC机房数据中心构建的电信大带宽,联通大带宽,移动大带宽,多线BGP大带宽租用,是为众多客户提供专业西部信息服务器托管报价,主机托管价格性价比高,为金融证券行业服务器托管,ai人工智能服务器托管提供bgp线路100M独享,G口带宽及机柜租用的专业成都idc公司。

具体内容如下

小程序开发中如何利用Tab实现一个滚动选项卡

最终效果如上。问题:

1、tab标题总共8个,所以一屏无法全部显示。
2、tab内容区左右滑动切换时,tab标题随即做标记(active)。
3、当active的标题不在当前屏显示时,要使其能显示到当前屏中。

一、wxml结构


tab标题因一排八个,所以使用 scroll-view组件,使其可横向滚动。
tab内容可左右滑动切换,使用swiper组件实现
为了偷懒,所以数据都通过wx:for遍历重复出来。

说明:

1、设置data-current属性用于:点击当前项时,通过点击事件swichNav中处理e.dataset.current取到点击的目标值。
2、swiper组件的current组件用于控制当前显示哪一页
3、swiper组件绑定change事件switchTab,通过e.detail.current拿到当前页

<view >
  <scroll-view scroll-x="true" class="tab-h" scroll-left="{{scrollLeft}}">
    <view class="tab-item {{currentTab==0&#63;'active':''}}" data-current="0" bindtap="swichNav">健康</view>
    <view class="tab-item {{currentTab==1&#63;'active':''}}" data-current="1" bindtap="swichNav">情感</view>
    <view class="tab-item {{currentTab==2&#63;'active':''}}" data-current="2" bindtap="swichNav">职场</view>
    <view class="tab-item {{currentTab==3&#63;'active':''}}" data-current="3" bindtap="swichNav">育儿</view>
    <view class="tab-item {{currentTab==4&#63;'active':''}}" data-current="4" bindtap="swichNav">纠纷</view>
    <view class="tab-item {{currentTab==5&#63;'active':''}}" data-current="5" bindtap="swichNav">青葱</view>
    <view class="tab-item {{currentTab==6&#63;'active':''}}" data-current="6" bindtap="swichNav">全部</view>
    <view class="tab-item {{currentTab==7&#63;'active':''}}" data-current="7" bindtap="swichNav">其他</view>
  </scroll-view>
  <swiper class="tab-content" current="{{currentTab}}" duration="300" bindchange="switchTab"
   >
    <swiper-item wx:for="{{[0,1,2,3,4,5,6,7]}}">
      <scroll-view scroll-y="true" class="scoll-h" >
        <block wx:for="{{[1,2,3,4,5,6,7,8]}}" wx:key="*this">
          <view class="item-ans">
            <view class="avatar">
              <image class="img" src="/avatar.png"></image>
            </view>
            <view class="expertInfo">
              <view class="name">欢颜</view>
              <view class="tag">知名情感博主</view>
              <view class="answerHistory">134个回答,2234人听过 </view>
            </view>
            <navigator url="/pages/askExpert/expertDetail" class="askBtn">问TA</navigator> 
          </view>
        </block>
      </scroll-view>
    </swiper-item>
  </swiper>
</view>

网站名称:小程序开发中如何利用Tab实现一个滚动选项卡-创新互联
本文来源:https://www.cdcxhl.com/article34/geope.html

成都网站建设公司_创新互联,为您提供外贸建站商城网站外贸网站建设ChatGPT软件开发定制网站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网站建设