实现效果:
wxml代码:
<view class='history_con'>
<block wx:for="{{historyTodayData}}" wx:key="year" data-index="{{index}}">
<view class='history_item_list'>
<text class="iconfont icon-timefill "></text>
<view class='histor_item {{index==historyTodayData.length-1?"last":""}}'>
<view class='histor_item_year'>{{item.year}}年</view>
<view class='histor_item_tit'>{{item.title}}</view>
</view>
</view>
</block>
</view>
historyTodayData实际为所需展示的数据,结构为对象数组。时间轴样式主要通过定位实现,轴线实际为border-left实现,为完美展示需要对最后一个元素做特殊处理,因此通过判断 index==historyTodayData.length-1 时动态添加类名,不显示border。
wxss代码:
page{
background: #f0f2f5;
}
.history_con{
padding:16px;
}
.history_item_list{
padding-left: 80px;
padding-right: 24px;
font-size:14px;
color:#666;
}
.iconfont{
color:#409eff94;
}
.histor_item{
border-left: 1px solid #409eff94;
height: 80px;
margin:-6px 0 -6px 7px;
position: relative;
}
.last{
border:none;
height: 32px;
}
.histor_item_year{
position: absolute;
left: -66px;
top: -18px;
}
.histor_item_tit{
position: absolute;
top: -18px;
left: 32px;
}