美文网首页
微信小程序实现标签页滑块效果

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

作者: 魔王哪吒 | 来源:发表于2018-12-14 13:13 被阅读61次
标题图

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

案例一

小程序完整代码:

wxml:

<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:

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:

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:

{
  "navigationBarTitleText": "消息"
}

案例二:

效果图:

案例二

相关文章

网友评论

      本文标题:微信小程序实现标签页滑块效果

      本文链接:https://www.haomeiwen.com/subject/yoiwhqtx.html