微信小程序开发之『顶部导航』特效

之前Android开发时,顶部导航用到viewPage,微信小程序里想要达到同样的效果,可用swiper来实现;先看效果图

微信小程序开发之『顶部导航』特效_第1张图片

上代码:

1.swiperTab.js

Page({
    data: {
        // tab切换  
        currentTab: 0,
    },
    swichNav: function (e) {
        console.log(e);
        var that = this;
        if (this.data.currentTab === e.target.dataset.current) {
            return false;
        } else {
            that.setData({
                currentTab: e.target.dataset.current,
            })
        }
    },
    swiperChange: function (e) {
        console.log(e);
        this.setData({
            currentTab: e.detail.current,
        })

    },
    onLoad: function (options) {
        // 生命周期函数--监听页面加载
    },
    onReady: function () {
        // 生命周期函数--监听页面初次渲染完成
    },
    onShow: function () {
        // 生命周期函数--监听页面显示
    },
    onHide: function () {
        // 生命周期函数--监听页面隐藏
    },
    onUnload: function () {
        // 生命周期函数--监听页面卸载
    },
    onPullDownRefresh: function () {
        // 页面相关事件处理函数--监听用户下拉动作
    },
    onReachBottom: function () {
        // 页面上拉触底事件的处理函数
    },
    onShareAppMessage: function () {
        // 用户点击右上角分享
        return {
            title: 'title', // 分享标题
            desc: 'desc', // 分享描述
            path: 'path' // 分享路径
        }
    }
})

2. swiperTab .wxml



  
  
    Tab1
    Tab2
    Tab3
  

  
  
    
      我是tab1
    
    
      我是tab2
    
    
      我是tab3
    
  

3. swiperTab .wxss

.page {
  margin-left: 10rpx;
  margin-right: 10rpx;
}

.swiper-tab {
  display: flex;
  flex-direction: row;
  line-height: 80rpx;
  border-bottom: 2rpx solid #777;
}

.tab-item {
  width: 33.3%;
  text-align: center;
  font-size: 15px;
  color: #777;
}

.swiper {
  height: 1100px;
  background: #dfdfdf;
}

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




你可能感兴趣的:(微信小程序开发)