微信小程序导航栏跟随滑动效果的实现代码


Posted in Javascript onMay 14, 2019

效果图

微信小程序导航栏跟随滑动效果的实现代码

.wxml

<view class='tabBar'>
<view class='tabItem wx:if="{{tabClick===0?"click":""}}"' bindtap='clickTab' data-index='0'>tab1</view>
<view class='tabItem wx:if="{{tabClick===1?"click":""}}"' bindtap='clickTab' data-index='1'>tab2 </view>
<view class='tabItem wx:if="{{tabClick===2?"click":""}}"' bindtap='clickTab' data-index='2'>tab3 </view>
<view class='underline' animation="{{animationData}}" style='left:{{isLeft}}'></view>
</view>

.wxss

.tabBar{
height: 80rpx;
background-color:#50B7EA;
width: 100%;
font-size: 28rpx;
color: rgba(255,255,255,0.50);
position: fixed;
top: 0;
left: 0;
display: flex;
justify-content: center;
align-items: center;
z-index: 997;
}
.tabItem{
width: 33.333%;
display: flex;
align-content: center;
justify-content: center;
position: relative;
height: 100%;
font-size: 28rpx;
}
.click{
color: white;
}
.underline{
position: absolute;
content: '';
width: 84rpx;
height: 3px;
background-color:white;
bottom: 0;
}

.js

data:{
tabClick: 0,
animationData: {},
 isLeft: '12%'
},
swiperTab: function (e) {
var that = this;
var index = e.detail.current
console.log(e.detail.current)
var animation = wx.createAnimation({
duration: 1000,
timingFunction: "ease",
})
this.animation = animation
if (index === 0) {
animation.translate(0, 0).step();
that.setData({
animationData: animation.export()
})
that.setData({
tabClick: e.detail.current
});
} else if (index === 1) {
var w = wx.getSystemInfoSync().windowWidth;
w = w * 0.32
animation.translate(w, 0).step();
that.setData({
animationData: animation.export()
})
that.setData({
tabClick: e.detail.current
});
} else if(index === 2){
var w = wx.getSystemInfoSync().windowWidth;
w = w * 0.65
animation.translate(w, 0).step();
that.setData({
animationData: animation.export()
})
that.setData({
tabClick: e.detail.current
});
}
},

总结 

以上所述是小编给大家介绍的微信小程序导航栏跟随滑动效果的实现代码,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

Javascript 相关文章推荐
javascript function、指针及内置对象
Feb 19 Javascript
基于Jquery的回车成tab焦点切换效果代码(Enter To Tab )
Nov 14 Javascript
JQuery UI的拖拽功能实现方法小结
Mar 14 Javascript
JavaScript基础知识学习笔记
Dec 02 Javascript
javascript实现dom动态创建省市纵向列表菜单的方法
May 14 Javascript
轻松掌握JavaScript中介者模式
Aug 26 Javascript
javascript基于原型链的继承及call和apply函数用法分析
Dec 15 Javascript
Vue.js对象转换实例
Jun 07 Javascript
node.js实现为PDF添加水印的示例代码
Dec 05 Javascript
vue-cli3 从搭建到优化的详细步骤
Jan 20 Javascript
node.JS事件机制与events事件模块的使用方法详解
Feb 06 Javascript
JS相册图片抖动放大展示效果的示例代码
Jan 29 Javascript
详解VSCode配置启动Vue项目
May 14 #Javascript
微信小程序下拉菜单效果的实例代码
May 14 #Javascript
jquery+css实现Tab栏切换的代码实例
May 14 #jQuery
jquery实现二级导航下拉菜单效果实例
May 14 #jQuery
js纯前端实现腾讯cos文件上传功能的示例代码
May 14 #Javascript
解决 viewer.js 动态更新图片导致无法预览的问题
May 14 #Javascript
vue如何获取自定义元素属性参数值的方法
May 14 #Javascript
You might like
PHP 中执行系统外部命令
2006/10/09 PHP
php快速url重写更新版[需php 5.30以上]
2010/04/25 PHP
10条PHP高级技巧[修正版]
2011/08/02 PHP
php处理抢购类功能的高并发请求
2018/02/08 PHP
图片动画横条广告带上下滚动的JS代码
2013/10/25 Javascript
jquery实现鼠标经过显示下划线的渐变下拉菜单效果代码
2015/08/24 Javascript
jQuery之动画效果大全
2016/11/09 Javascript
js实现用户输入的小写字母自动转大写字母的方法
2017/01/21 Javascript
vue中引用阿里字体图标的方法
2018/02/10 Javascript
JavaScript模板引擎实现原理实例详解
2018/12/14 Javascript
layui 上传插件 带预览 非自动上传功能的实例(非常实用)
2019/09/23 Javascript
vue实现简单图片上传
2020/06/30 Javascript
Python 常用string函数详解
2016/05/30 Python
python字符串中的单双引
2017/02/16 Python
如何用Python实现简单的Markdown转换器
2018/07/16 Python
修改默认的pip版本为对应python2.7的方法
2018/11/06 Python
解决Django 在ForeignKey中出现 non-nullable field错误的问题
2019/08/06 Python
win10系统Anaconda和Pycharm的Tensorflow2.0之CPU和GPU版本安装教程
2019/12/03 Python
Windows10+anacond+GPU+pytorch安装详细过程
2020/03/24 Python
使用python matplotlib 画图导入到word中如何保证分辨率
2020/04/16 Python
pycharm下pyqt4安装及环境配置的教程
2020/04/24 Python
对python中arange()和linspace()的区别说明
2020/05/03 Python
Python常见反爬虫机制解决方案
2020/06/01 Python
详解Python中的文件操作
2021/01/14 Python
全面总结使用CSS实现水平垂直居中效果的方法
2016/03/10 HTML / CSS
Laura Geller官网:美国彩妆品牌
2018/12/29 全球购物
Timberland俄罗斯官方网上商店:全球领先的户外品牌
2020/03/15 全球购物
Java servlet面试题
2012/03/04 面试题
公司委托书范本
2014/04/04 职场文书
大学优秀班集体申报材料
2014/05/23 职场文书
令人印象深刻的自荐信
2014/05/25 职场文书
解除劳动关系协议书范文
2014/09/11 职场文书
小人国观后感
2015/06/11 职场文书
大学生见习总结报告
2015/06/24 职场文书
运动会通讯稿600字
2015/07/20 职场文书
使用GO语言实现Mysql数据库CURD的简单示例
2021/08/07 Golang