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

小程序完整代码:

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": "消息"
}

案例二:

效果图:

代码:

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

达叔小生:往后余生,唯独有你

You and me, we are family !

90后帅气小伙,良好的开发习惯;独立思考的能力;主动并且善于沟通

简书博客: 达叔小生

https://www.jianshu.com/u/c785ece603d1

结语

  • 下面我将继续对 其他知识 深入讲解 ,有兴趣可以继续关注
  • 小礼物走一走 or 点赞

微信小程序实现标签页滑块效果的更多相关文章

  1. 微信小程序里实现跑马灯效果

    在微信小程序 里实现跑马灯效果,类似滚动字幕或者滚动广告之类的,使用简单的CSS样式控制,没用到JS wxml: <!-- 复制的跑马灯效果 --> <view class=&quo ...

  2. 微信小程序实现“鲜肉APP”首页效果

    项目地址http://git.oschina.net/djcx/WeiXinXiaoChengXu/tree/master 如果您觉得不错,记得给一个star 由于微信小程序目前是当下趋势,正好昨天弄 ...

  3. Java的家庭记账本程序(H) :微信小程序 image 标签,在模拟器中无法显示图片?(已解决)

    日期:2019.2.25 博客期:036 星期一 吼!今天我还是继续研究了自己的微信小程序,还没有连接数据库,只是在xml的设计上添加了不少东西,大家可以看我的截图,嗯~说到今天的收获,就是 marg ...

  4. 微信小程序新闻网站列表页

    在app.json中可以设置所有文件的头部导航颜色 (是window属性的子属性) 在具体页面可以单独设置该页面的导航颜色 (直接写该属性,不需要写window属性) 查看官方文档,可以看到好多全局属 ...

  5. 微信小程序text标签

    最近在做小程序,使用<text>标签的时候发现里面的文本text-family不生效, 经过试验,发现直接在text标签的class设置不生效,可以在外层包一个父元素就可以设置了. < ...

  6. 微信小程序之启动页的重要性

    启动页在APP中是个很常见的需求,为什么对于小程序来说也非常重要呢?首先我描述一下我在开发过程中遇到的一些问题以及解决的步骤,到最后为什么要加启动页,看完你就明白了. 小程序的首页需要展示用户关注的小 ...

  7. 微信小程序实现左滑删除效果(原生/uni-app)

    实现效果 列表中侧滑删除 删除不同时存在 scrollview上下滑动与侧滑删除不影响 uni-app实现 html部分 <template> <scroll-view :scrol ...

  8. 微信小程序的标签和html标签比较

    html 小程序 <div></div> <view></view> <h1><h2>....<h6> <p& ...

  9. 微信小程序swiper标签的测试

    swiper属性(具体看官方文档): 一:testswiper.wxml的代码如下.testswiper.js自动生成示例代码. //testswiper.wxml <view > < ...

随机推荐

  1. 5个数组Array方法: indexOf、filter、forEach、map、reduce使用实例

    ES5中,一共有9个Array方法 Array.prototype.indexOf Array.prototype.lastIndexOf Array.prototype.every Array.pr ...

  2. java maven compiler设置默认1.8

    方法一: <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupI ...

  3. centos 7 安装vscode

    网上很多写的安装,会遇到一个问题,就是无法启动: sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc sudo sh ...

  4. mac电脑使用技巧和相关快捷键

    移动与选取 1. 光标移动 刚从 Windows 转过来的时候可能会发现,Mac 上没有 Home 和 End 键.其实,直接这样就好了: Cmd + ←  移至行首 (Home)Cmd + →  移 ...

  5. 泡泡堂BNB[ZJOI2008]

    --BZOJ1034 Description 第XXXX届NOI期间,为了加强各省选手之间的交流,组委会决定组织一场省际电子竞技大赛,每一个省的代表队由n名选手组成,比赛的项目是老少咸宜的网络游戏泡泡 ...

  6. 【Java】a++,++a 区分记忆

    写了个例子测试: package com.xdsux.java.basetest; public class BaseTest1 { public static void main(String[] ...

  7. 基于百词斩和扇贝单词的背单词APP软件测试

    概述 背单词APP是非常受大学生青睐的手机应用,但它的发展尚未成熟,存在一些缺陷.我们决定深入地分析一组典型的背单词APP:百词斩(A产品).扇贝单词(B产品),寻找当前背单词APP中的提升空间.下面 ...

  8. Cookie保存中文用户名报错(500)

    在用Cookie保存用户名时候,当用户名是中文的时候服务器报错了. HTTP Status 500 - An exception occurred processing JSP page /dolog ...

  9. python的文件读写笔记

    读写文件是最常见的IO操作.Python内置了读写文件的函数,用法和C是兼容的. 读写文件前,我们先必须了解一下,在磁盘上读写文件的功能都是由操作系统提供的,现代操作系统不允许普通的程序直接操作磁盘, ...

  10. 如何在Ubuntu上安装LAMP服务器系统?

    在Ubuntu上安装LAMP Ubuntu的开发人员让人们很容易安装和配置LAMP软件包,只要借助一个终端命令.所以,打开终端窗口,让我们开始入手吧. sudo apt-get install lam ...