当她不爱你的时候,就是你从他生活中消失的时候,在第一时间离开她,骄傲地过属于自己的生活。同时,你也希望她能幸福快乐,希望她找到属于她的未来。我们就轻轻拥抱一下回忆里的温暖。
本文主要介绍了如何实现小程序tab栏下划线动画效果,分享给大家,具体如下:
最终效果
实现
wxml
<view class='abox'>
<view wx:for="{{title}}" class='{{currentIndex==index?"tabTrue":""}}' bindtap='changeTab' data-aa='{{index}}'>
{{item}}
</view>
<view class='b' style="left:{{left}}px"></view>
</view>
wxss
.abox{
display: flex;
flex-direction: row;
width: 100%;
justify-content: space-around;
position: relative;
padding-bottom: 20rpx;
}
.tabTrue{
color: red;
}
.b{
background: red;
height: 4rpx;
width:64rpx;
position: absolute;
bottom: 0;
transition: all .3s linear;
}
js
Page({
data: {
title: ["首页","掘金","思否","知乎"],
currentIndex:"0",
left:""
},
changeTab:function(e){
//console.log(e)
this.setData({
currentIndex: e.currentTarget.dataset.aa
})
this.changeline(e)
},
changeline:function(){
const query = wx.createSelectorQuery()
var _this = this
query.select('.tabTrue').boundingClientRect()
query.exec(function (res) {
_this.setData({
left: res[0].left
})
//console.log(res[0].left)
})
},
onLoad: function () {
this.changeline(1)
}
})
上面代码可以实现效果,这里面最重要的就是通过 changeTab方法获取有tabtrue这个class的标签,获取到标签的left值。
到此这篇关于如何实现小程序tab栏下划线动画效果就介绍到这了。当你的才华还撑不起你的野心时,那你就应该静下心来学习。更多相关如何实现小程序tab栏下划线动画效果内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!