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

小程序完整代码:

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. C#使用CefSharp开源库开发Chrome 浏览器

    一.介绍        这个东西我以前没有接触过,但是公司项目里面有用到这个东西,所以就顺便研究一下.今天只是做了 WinForm 的测试,有时间了在试试 WPF 是如何实现的.刚开始一塌糊涂,有点麻 ...

  2. centos 批量杀死进程

    ps aux | grep 进程名| grep -v grep | awk '{print $2}' | xargs kill -9

  3. NC 刷新后,停留上一次选择的行(多行)

    如图,我点击批量输入后,会调用列表刷新按钮.但数据之前选择的光标会跳到第一行,原先选择的行就不知道是哪行可.图为最终效果 // 批量输入日期后实时刷新 apply update(batch input ...

  4. 【Linux】vim的使用

    使用vi和vim的原因:linux很多软件默认调用vi进行编辑,因此有必要熟悉它的使用规则 vi: 打开文件: vi 文件名 [一般模式]打开文件时进入一般模式,这个模式下的操作: 上下左右移动光标 ...

  5. 【此处有干货~】jmeter+ant+jenkins持续集成配置及过程中问题解决思路

    本人是一枚工作近三年的小测试,大学正好专业为软件测试,在工作中用到最多的是功能测试.接口测试.压力测试.偶尔会涉及到性能测试......(小白,很多观念技术跟大佬差距太大,勿喷) 在接口测试过程当中, ...

  6. 关于Visual Studio调试C/C++,JS,PHP,JAVA,Python等语言的方法

    我在开始接触vs code后,确实对它的高颜值和小巧灵活而着迷,但是有一个非常现实的问题,相对于vs来说,vscode是一个代码编辑器,而不是一个IDE,在代码编译运行上存在着极大的问题,尤其是开始编 ...

  7. 学习Acegi应用到实际项目中(9)- 实现FilterInvocationDefinition

    在实际应用中,开发者有时需要将Web资源授权信息(角色与授权资源之间的定义)存放在RDBMS中,以便更好的管理.事实上,一般的企业应用都应当如此,因为这样可以使角色和Web资源的管理更灵活,更自由.那 ...

  8. centos7下安装mysql会遇到的问题集合

    1.mysqld_safe提示 command not found 解决方法 https://blog.csdn.net/lampqiu/article/details/79138961 2.Mysq ...

  9. mount的几个选项

    一.mount -o noatime表示在读文件时不去更改文件的access time属性了,所以该选项会提升mount操作的执行效率. 二.mount --bind:等同于 -o bind可用于挂载 ...

  10. 在windows系统安装pygame项目

    STEP1: 下载安装程序 访问https://bitbucket.org/pygame/pygame/downloads/,查找与你运行的Python版本匹配的安装程序,如果找不到,可以去https ...