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


    标题图

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

    案例一

    小程序完整代码:

    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;
       100%;
      text-align: center;
      line-height: 80rpx;
    }
    
    .swiper-tab-list {
      font-size: 30rpx;
      display: inline-block;
       33.33%;
      color: #797979;
    }
    
    .on {
      color: #ca0c16;
      border-bottom: 5rpx solid #ca0c16;
    }
    
    .swiper-box {
      display: block;
      height: 100%;
       100%;
      overflow: hidden;
    }
    
    .img {
       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": "消息"
    }
    

    案例二:

    效果图:

    案例二

    代码:

    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>
    <swiper current="{{currentTab}}" class="swiper-box" duration="300" style="height:{{winHeight - 31}}px" bindchange="bindChange">
      <swiper-item>
      </swiper-item>
    
      <swiper-item>
      </swiper-item>
    </swiper>
    

    js:

    Page({
    
      /**
       * 页面的初始数据
       */
      data: {
        winWidth: 0,
        winHeight: 0,
        currentTab: 0,
      },
      // 滑动切换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
          })
        }
      },
      /**
       * 生命周期函数--监听页面加载
       */
      onLoad: function(options) {
    
      },
    
      /**
       * 生命周期函数--监听页面初次渲染完成
       */
      onReady: function() {
        var that = this;
        wx.getSystemInfo({
          success: function(res) {
            that.setData({
              winWidth: res.windowWidth,
              winHeight: res.windowHeight
            });
          }
        });
      },
    
      /**
       * 生命周期函数--监听页面显示
       */
      onShow: function() {
    
      },
    
      /**
       * 生命周期函数--监听页面隐藏
       */
      onHide: function() {
    
      },
    
      /**
       * 生命周期函数--监听页面卸载
       */
      onUnload: function() {
    
      },
    
      /**
       * 页面相关事件处理函数--监听用户下拉动作
       */
      onPullDownRefresh: function() {
    
      },
    
      /**
       * 页面上拉触底事件的处理函数
       */
      onReachBottom: function() {
    
      },
    
      /**
       * 用户点击右上角分享
       */
      onShareAppMessage: function() {
    
      }
    })
    

    wxss:

    Page {
      background-color: #f1f1f1;
    }
    
    .swiper-tab {
      background-color: #fff;
       100%;
      text-align: center;
      line-height: 80rpx;
    }
    
    .swiper-tab-list {
      font-size: 30rpx;
      display: inline-block;
       50%;
      color: #797979;
    }
    
    .on {
      color: #5fdafe;
      border-bottom: 5rpx solid #30d1ff;
    }
    
    .swiper-box {
      display: block;
      height: 100%;
       100%;
      overflow: hidden;
    }
    

    达叔小生:往后余生,唯独有你
    You and me, we are family !
    90后帅气小伙,良好的开发习惯;独立思考的能力;主动并且善于沟通
    简书博客: 达叔小生
    https://www.jianshu.com/u/c785ece603d1

    结语

    • 下面我将继续对 其他知识 深入讲解 ,有兴趣可以继续关注
    • 小礼物走一走 or 点赞
  • 相关阅读:
    ORALE 误删表 Flashback 恢复表
    C# SAP Connector .NET Framework 4.5 版本下载
    C# VS 调试报错:未能加载文件或程序集“Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”或它的某一个依赖项
    【转载】亚信防毒墙网络版卸载
    CSS 相邻兄弟选择器
    如何衡量一个人的 JavaScript 水平
    this软绑定
    RequireJS
    模块机制
    Javascript 数组循环遍历之forEach
  • 原文地址:https://www.cnblogs.com/dashucoding/p/10118881.html
Copyright © 2020-2023  润新知