前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【小程序UI教程】小程序滑动选择tab-view

【小程序UI教程】小程序滑动选择tab-view

作者头像
用户5997198
发布2019-09-20 16:22:51
8950
发布2019-09-20 16:22:51
举报
文章被收录于专栏:蚂蚁开源社区蚂蚁开源社区

功能

可以来回滑动得tab-view功能,小程序实现

在android ios 平台测试过,确保真实环境一致

如何使用

复制page下的文件夹到自己项目中

配置app.json

具体教程查看解压包demo导入说明

index.wxml

代码语言:javascript
复制
<view class="stv-container">
  <view class="tab-bar">
    <view wx:for="{{tabs}}" wx:key="unique" data-index=
    "{{index}}" bindtap="handlerTabTap" class="tab {{activeTab==index?'tab-active':''}}" style="width: {{stv.windowWidth/tabs.length}}px">
      <text>{{item}}</text>
    </view>
    <view style="width: {{stv.lineWidth}}px; left: {{stv.offset/tabs.length}}px" class="under-line {{!stv.tStart? 'withAnimate': ''}}"></view>
  </view>
  <view class="scroll-view">
    <view bindtouchstart="handlerStart" catchtouchmove="handlerMove" bindtouchcancel="handlerCancel" bindtouchend="handlerEnd"  class="scroll-view-wrapper {{!stv.tStart? 'withAnimate': ''}}" style="left: -{{stv.offset}}px">
      <view style="width: {{stv.windowWidth}}px;" wx:for="{{tabs}}" wx:key="unique" class="one-scene">
        <scroll-view style="height:100%" scroll-y>
          <view wx:for="1234567777777" wx:key="unique">
            <text>这是第{{index+1}}个页面</text>
          </view>
        </scroll-view>
      </view>
    </view>
  </view>
</view>

index.wxss

代码语言:javascript
复制
.stv-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}
.withAnimate {
  transition: all 100ms ease;
  -webkit-transform: translate3d(0, 0, 0);
  -moz-transform: translate3d(0, 0, 0);
  -ms-transform: translate3d(0, 0, 0);
  transform: translate3d(0, 0, 0);
  -webkit-backface-visibility: hidden;
  -moz-backface-visibility: hidden;
  -ms-backface-visibility: hidden;
  backface-visibility: hidden;
  -webkit-perspective: 1000;
  -moz-perspective: 1000;
  -ms-perspective: 1000;
  perspective: 1000;
}
.stv-container .tab-bar {
  position: relative;
  display: flex;
  font-size: 30rpx;
  color: #666666;
}
.stv-container .tab-bar .tab-active {
  color: #2d80ff;
}
.stv-container .tab-bar .tab {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 16rpx;
  padding-bottom: 20rpx;
}
.stv-container .tab-bar .under-line {
  position: absolute;
  bottom: 0;
  height: 6rpx;
  background-color: #2d80ff;
}
.stv-container .scroll-view {
  position: relative;
  width: 100%;
  height: 100%;
  background: #e7eaef;
}
.stv-container .scroll-view .scroll-view-wrapper {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
}
.stv-container .scroll-view .scroll-view-wrapper .one-scene {
  height: 100%;
}
.one-scene text {
  display: flex;
  justify-content: center;
  padding-top: 200rpx;
}

作者 | 时期 | 蚂蚁开源社区大神,资深开发工程师

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2019-09-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 蚂蚁大喇叭 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云开发 CloudBase
云开发(Tencent CloudBase,TCB)是腾讯云提供的云原生一体化开发环境和工具平台,为200万+企业和开发者提供高可用、自动弹性扩缩的后端云服务,可用于云端一体化开发多种端应用(小程序、公众号、Web 应用等),避免了应用开发过程中繁琐的服务器搭建及运维,开发者可以专注于业务逻辑的实现,开发门槛更低,效率更高。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档