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


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 相关文章推荐
jQuery+.net实现浏览更多内容(改编php版本)
Mar 28 Javascript
jquery.cookie() 方法的使用(读取、写入、删除)
Dec 05 Javascript
javascript调试之DOM断点调试法使用技巧分享
Apr 15 Javascript
使用GruntJS构建Web程序之Tasks(任务)篇
Jun 06 Javascript
借助FileReader实现将文件编码为Base64后通过AJAX上传
Dec 24 Javascript
使用DeviceOne实现微信小程序功能
Dec 29 Javascript
React实现点击删除列表中对应项
Jan 10 Javascript
javascript中this用法实例详解
Apr 06 Javascript
gulp安装以及打包合并的方法教程
Nov 19 Javascript
vue实现提示保存后退出的方法
Mar 15 Javascript
js实现倒计时器自定义时间和暂停
Feb 25 Javascript
微信小程序实现3D轮播图效果(非swiper组件)
Sep 21 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
一些星际专用术语解释
2020/03/04 星际争霸
PHP 实现多服务器共享 SESSION 数据
2009/08/15 PHP
php自动加载autoload机制示例分享
2014/02/20 PHP
ThinkPHP CURD方法之field方法详解
2014/06/18 PHP
PHP连接access数据库
2015/03/27 PHP
php验证码实现代码(3种)
2015/09/07 PHP
Symfony2之session与cookie用法小结
2016/03/18 PHP
PHP正则删除HTML代码中宽高样式的方法
2017/06/12 PHP
Laravel 5.5官方推荐的Nginx配置学习教程
2017/10/06 PHP
从阶乘函数对比Javascript和C#的异同
2012/05/31 Javascript
javascript:文字不间断向左移动的实例代码
2013/08/08 Javascript
document.compatMode的CSS1compat使用介绍
2014/04/03 Javascript
jQuery实现带滑动条的菜单效果代码
2015/08/26 Javascript
基于Javascript实现弹出页面效果
2016/01/01 Javascript
详解JavaScript中的自定义事件编写
2016/05/10 Javascript
简单掌握JavaScript中const声明常量与变量的用法
2016/05/21 Javascript
JS库之Three.js 简易入门教程(详解之一)
2017/09/13 Javascript
jquery动态添加带有样式的HTML标签元素方法
2018/02/24 jQuery
node中使用es6/7/8(支持性与性能)
2019/03/28 Javascript
记一次用vue做的活动页的方法步骤
2019/04/11 Javascript
Vue数字输入框组件使用方法详解
2020/02/10 Javascript
深入浅析Python中join 和 split详解(推荐)
2016/06/30 Python
Python 使用SMTP发送邮件的代码小结
2016/09/21 Python
python利用rsa库做公钥解密的方法教程
2017/12/10 Python
Python基于dom操作xml数据的方法示例
2018/05/12 Python
python如何制作缩略图
2019/04/30 Python
Python利用命名空间解析XML文档
2020/08/10 Python
CSS3打造百度贴吧的3D翻牌效果示例
2017/01/04 HTML / CSS
AE美国鹰美国官方网站:American Eagle Outfitters
2016/08/22 全球购物
圣彼得堡鲜花配送:Semicvetic
2020/09/15 全球购物
一百多行代码实现react拖拽hooks
2021/03/23 Javascript
创建服务型党组织实施方案
2014/02/25 职场文书
银行奉献演讲稿
2014/09/16 职场文书
小组口号霸气押韵
2015/12/24 职场文书
pytest配置文件pytest.ini的详细使用
2021/04/17 Python
Go获取两个时区的时间差
2022/04/20 Golang