前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >微信小程序实现标签页滑块效果

微信小程序实现标签页滑块效果

作者头像
达达前端
发布2019-07-04 21:03:41
1.9K0
发布2019-07-04 21:03:41
举报
文章被收录于专栏:达达前端

微信小程序实现标签页滑块效果

案例一

小程序完整代码:

wxml:

代码语言:javascript
复制
<view class="swiper-tab">
  <view class="swiper-tab-list {{currentTab==0 ? 'on' : ''}}" data-current="0" bindtap="swichNav">留言</view>
  <view class="swiper-tab-list {{currentTab==1 ? 'on' : ''}}" data-current="1" bindtap="swichNav">活动</view>
  <view class="swiper-tab-list {{currentTab==2 ? 'on' : ''}}" data-current="2" bindtap="swichNav">更多</view>
</view>
<swiper current="{{currentTab}}" class="swiper-box" duration="300" style="height:{{winHeight - 31}}px" bindchange="bindChange">
  <swiper-item>
    <view>
      <image src='{{image}}' class='img'></image>
    </view>
  </swiper-item>

  <swiper-item>
    <view>
      <image src='{{image}}' class='img'></image>
    </view>
  </swiper-item>

  <swiper-item>
    <view>
      <image src='{{image}}' class='img'></image>
    </view>
  </swiper-item>
  
</swiper>

wxss:

代码语言:javascript
复制
Page {
  background-color: #f1f1f1;
}

.swiper-tab {
  background-color: #fff;
  width: 100%;
  text-align: center;
  line-height: 80rpx;
}

.swiper-tab-list {
  font-size: 30rpx;
  display: inline-block;
  width: 33.33%;
  color: #797979;
}

.on {
  color: #ca0c16;
  border-bottom: 5rpx solid #ca0c16;
}

.swiper-box {
  display: block;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

.img {
  width: 100%;
  height: 540rpx;
}

js:

代码语言:javascript
复制
Page({
  data: {
    winWidth: 0,
    winHeight: 0,
    currentTab: 0,
    image: "../../images/404.png",
  },
  onLoad: function(options) {

  },
  onReady: function() {
    var that = this;
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }
    });
  },
  // 滑动切换tab
  bindChange: function(e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current
    });
  },
  // 点击tab切换
  swichNav: function(e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  onShow: function() {

  },
  onHide: function() {

  },
  onUnload: function() {

  },
})

json:

代码语言:javascript
复制
{
  "navigationBarTitleText": "消息"
}

案例二:

效果图:

案例二

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018.12.14 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

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

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

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