欢迎来到258分享网,纯净的网络源码分享基地!

258资源分享网

全部作品
全部作品
网站源码
微信源码
素材特效
源码插件
视频教程
建站学院
热门搜索: 织梦  农业种植  农业  安全设置  官方
258资源分享 > 建站学院 > 微信开发 > 微信小程序开发之『顶部导航』特效

推荐下载

HTML5响应式自适应网咯设计

2020-05-12   浏览:736

高端HTML5响应式企业通用网

2020-05-06   浏览:517

html5响应式外贸网站英文版

2020-05-08   浏览:505

HTML5自适应律师工作室类网

2020-04-04   浏览:501

HTML5影视传媒文化公司类网

2020-05-12   浏览:494

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

发布时间:2020-12-04  

作者:ruicoding,来自原文地址 
之前Android开发时,顶部导航用到viewPage,微信小程序里想要达到同样的效果,可用swiper来实现;

先看效果图

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

上代码: 
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

 

<view class="page">

 

<!--顶部导航栏-->

<view class="swiper-tab">

<view class="tab-item {{currentTab==0 ? 'on' : ''}}" data-current="0" bindtap="swichNav">Tab1</view>

<view class="tab-item {{currentTab==1 ? 'on' : ''}}" data-current="1" bindtap="swichNav">Tab2</view>

<view class="tab-item {{currentTab==2 ? 'on' : ''}}" data-current="2" bindtap="swichNav">Tab3</view>

</view>

 

<!--内容主体-->

<swiper class="swiper" current="{{currentTab}}" duration="200" bindchange="swiperChange">

<swiper-item>

<view>我是tab1</view>

</swiper-item>

<swiper-item>

<view>我是tab2</view>

</swiper-item>

<swiper-item>

<view>我是tab3</view>

</swiper-item>

</swiper>

</view>

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;

本文标签

:备案管家服务帮您把复杂流程变简单,解决您在进行网站备案过程中遇到的效率低下和成功率不高的问题。个人300/2个域名,企业500/5个域名,qq1650004.