结构如下
代码语言:javascript复制 <view class="car-tab d-flex j-sb a-center position-relative">
<view class="car-tab-itm position-relative {{index == bottomBar ? 'active' : ''}}" bindtap="changeBottomBar"
wx:for="{{types}}" data-index="{{index}}">
<text class="font-md text-light-dark-more">{{item.title}}</text>
</view>
</view>
样式
代码语言:javascript复制.car-tab {
box-sizing: border-box;
width: 692rpx;
height: 54rpx;
border-bottom: 2rpx solid #eee;
margin: 0 auto;
}
.car-tab-itm {
box-sizing: border-box;
width: 100%;
text-align: center;
height: 54rpx;
padding-bottom: 6rpx;
}
.car-tab-itm.active {
border-bottom:4rpx solid #ff7a1c;
}
以这种思路去实现的,与设计图差距很大
设计图的效果是边框圆角 且 高亮边框有种相对于长边框的垂直居中效果
如果要实现这种效果,高亮边框就不能使用border
属性来实现了。 这里我的思路是将高亮边框用div实现代码如下
结构
代码语言:javascript复制 <view class="car-tab d-flex j-sb a-center position-relative">
<view class="car-tab-itm position-relative {{index == bottomBar ? 'active' : ''}}" bindtap="changeBottomBar"
wx:for="{{types}}" data-index="{{index}}">
<text class="font-md text-light-dark-more">{{item.title}}</text>
<view class="car-tab-itm-border" wx:if="{{index == bottomBar}}">
</view>
</view>
</view>
样式
代码语言:javascript复制.car-tab {
box-sizing: border-box;
width: 692rpx;
height: 54rpx;
border-bottom: 2rpx solid #eee;
margin: 0 auto;
}
.car-tab-itm {
box-sizing: border-box;
width: 100%;
text-align: center;
height: 54rpx;
padding-bottom: 6rpx;
}
.car-tab-itm-border {
position: absolute;
bottom: -2rpx;
left: 0;
display: inline-block;
width: inherit;
height: 4rpx;
background: #ff7a1c;
border-radius: 2rpx;
}
ui的基本效果已经实现 接下来我们给元素加点效果,现在切换太生硬了。。。 添加宽度双向变化效果
参考demo
结构
代码语言:javascript复制<view class="car-tab d-flex j-sb a-center position-relative">
<view class="car-tab-itm position-relative {{index == bottomBar ? 'active' : ''}}" bindtap="changeBottomBar"
wx:for="{{types}}" data-index="{{index}}">
<text class="font-md text-light-dark-more">{{item.title}}</text>
<view class="car-tab-itm-border" wx:if="{{index == bottomBar}}">
<view class="real-border"></view>
</view>
</view>
</view>
样式
代码语言:javascript复制.car-tab {
box-sizing: border-box;
width: 692rpx;
height: 54rpx;
border-bottom: 2rpx solid #eee;
margin: 0 auto;
}
.car-tab-itm {
box-sizing: border-box;
width: 100%;
text-align: center;
height: 54rpx;
padding-bottom: 6rpx;
}
.car-tab-itm-border {
position: absolute;
bottom: -2rpx;
left: 0;
display: inline-block;
width: inherit;
height: 4rpx;
/* background: #ff7a1c; */
/* border-radius: 2rpx; */
text-align: center;
}
.real-border {
display: inline-block;
width: inherit;
height: 4rpx;
background: #ff7a1c;
border-radius: 2rpx;
margin-bottom:30rpx;
animation: widthSlide .3s linear;
}
@keyframes widthSlide {
from {
width: 0;
}
to {
width: inherit;
}
}
实现效果
机子上跑很流畅,gif录制的很卡。。。。