微信小程序?qū)崿F(xiàn)列表滾動頭部吸頂?shù)氖纠a
本文介紹了小程序頭部吸頂?shù)膶崿F(xiàn)代碼示例,分享給大家,也給自己留個筆記
demo 地址: https://github.com/iotjin/Jh_weapp
效果圖:

吸頂主要是 position: sticky;
.header {
background: rgb(230, 230, 230);
height: 25px;
line-height: 25px;
padding-left: 30rpx;
font-size: 13px;
align-items: center;
position: sticky;
top: 0;
}
js 代碼:
Page({
data: {
dataArr: [{
"AB_MonthDay": "30/06",
"AB_ZhiChu": "1111",
"AB_ShouRu": "2222",
"AB_Bill": [{
"AB_LeiBie": "吃飯1",
"AB_Money": "11",
"AB_Remark": "備注",
"AB_Date": "2011-11-11 15:38:16",
"AB_FenLei": "支出",
},{
"AB_LeiBie": "吃飯1",
"AB_Money": "22",
"AB_Remark": "備注2",
"AB_Date": "2011-11-11 15:38:16",
"AB_FenLei": "支出",
},{
"AB_LeiBie": "紅包1",
"AB_Money": "33",
"AB_Remark": "備注33",
"AB_Date": "2011-11-11 15:38:16",
"AB_FenLei": "收入",
},
]
},
{
"AB_MonthDay": "29/06",
"AB_ZhiChu": "1111",
"AB_ShouRu": "2222",
"AB_Bill": [{
"AB_LeiBie": "吃飯2",
"AB_Money": "22",
"AB_Remark": "",
"AB_Date": "2011-11-11 15:38:16",
"AB_FenLei": "支出",
}]
},
{
"AB_MonthDay": "28/06",
"AB_ZhiChu": "1111",
"AB_ShouRu": "2222",
"AB_Bill": [{
"AB_LeiBie": "吃飯3",
"AB_Money": "33",
"AB_Remark": "",
"AB_Date": "2011-11-11 15:38:16",
"AB_FenLei": "支出",
}]
},
{
"AB_MonthDay": "27/06",
"AB_ZhiChu": "1111",
"AB_ShouRu": "2222",
"AB_Bill": [{
"AB_LeiBie": "吃飯4",
"AB_Money": "44",
"AB_Remark": "",
"AB_Date": "2011-11-11 15:38:16",
"AB_FenLei": "支出",
}]
},
{
"AB_MonthDay": "26/06",
"AB_ZhiChu": "1111",
"AB_ShouRu": "2222",
"AB_Bill": [{
"AB_LeiBie": "吃飯4",
"AB_Money": "44",
"AB_Remark": "",
"AB_Date": "2011-11-11 15:38:16",
"AB_FenLei": "支出",
}]
},
{
"AB_MonthDay": "25/06",
"AB_ZhiChu": "1111",
"AB_ShouRu": "2222",
"AB_Bill": [{
"AB_LeiBie": "吃飯4",
"AB_Money": "44",
"AB_Remark": "",
"AB_Date": "2011-11-11 15:38:16",
"AB_FenLei": "支出",
}]
},
{
"AB_MonthDay": "24/06",
"AB_ZhiChu": "1111",
"AB_ShouRu": "2222",
"AB_Bill": [{
"AB_LeiBie": "吃飯4",
"AB_Money": "44",
"AB_Remark": "",
"AB_Date": "2011-11-11 15:38:16",
"AB_FenLei": "支出",
}]
},
{
"AB_MonthDay": "23/06",
"AB_ZhiChu": "1111",
"AB_ShouRu": "2222",
"AB_Bill": [{
"AB_LeiBie": "吃飯4",
"AB_Money": "44",
"AB_Remark": "",
"AB_Date": "2011-11-11 15:38:16",
"AB_FenLei": "支出",
}]
},
{
"AB_MonthDay": "22/06",
"AB_ZhiChu": "1111",
"AB_ShouRu": "2222",
"AB_Bill": [{
"AB_LeiBie": "吃飯4",
"AB_Money": "44",
"AB_Remark": "",
"AB_Date": "2011-11-11 15:38:16",
"AB_FenLei": "支出",
}]
},
{
"AB_MonthDay": "21/06",
"AB_ZhiChu": "1111",
"AB_ShouRu": "2222",
"AB_Bill": [{
"AB_LeiBie": "吃飯4",
"AB_Money": "44",
"AB_Remark": "",
"AB_Date": "2011-11-11 15:38:16",
"AB_FenLei": "支出",
}]
},
{
"AB_MonthDay": "20/06",
"AB_ZhiChu": "1111",
"AB_ShouRu": "2222",
"AB_Bill": [{
"AB_LeiBie": "吃飯4",
"AB_Money": "44",
"AB_Remark": "",
"AB_Date": "2011-11-11 15:38:16",
"AB_FenLei": "支出",
}]
},
{
"AB_MonthDay": "19/06",
"AB_ZhiChu": "1111",
"AB_ShouRu": "2222",
"AB_Bill": [{
"AB_LeiBie": "吃飯4",
"AB_Money": "44",
"AB_Remark": "",
"AB_Date": "2011-11-11 15:38:16",
"AB_FenLei": "支出",
}]
},
]
},
onShow: function () {
},
onPageScroll: function (res) {
console.log(res.scrollTop);
}
})
wxml 代碼:
<view class="main-bg">
<view wx:for="{{dataArr}}" wx:key="index" class="section">
<view class="header"> {{item.AB_MonthDay}}</view>
<view wx:for="{{item.AB_Bill}}" wx:key="index" class="cell">
<view class="row1">
<view wx:if="{{item.AB_Remark}}" class="leibie">{{item.AB_LeiBie}} · {{item.AB_Remark}}</view>
<view wx:else="{{!item.AB_Remark}}" class="leibie">{{item.AB_LeiBie}}</view>
<view class='{{item.AB_FenLei=="收入"?"money2":"money"}}'>{{item.AB_Money}}</view>
</view>
</view>
</view>
</view>
wxss 代碼:
.header {
background: rgb(230, 230, 230);
height: 25px;
line-height: 25px;
padding-left: 30rpx;
font-size: 13px;
align-items: center;
position: sticky;
top: 0;
}
.cell {
background: white;
height: 44px;
align-items: center;
line-height: 44px;
border-bottom: 1px solid rgb(230, 230, 230);
}
.row1 {
margin-left: 30rpx;
display: flex;
justify-content: space-between;
}
.leibie {
width: 70%;
font-size: 30rpx;
color: black;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
.money {
font-size: 32rpx;
color: black;
font-weight: bold;
margin-right: 30rpx;
}
.money2 {
font-size: 32rpx;
color: #38BC9D;
font-weight: bold;
margin-right: 30rpx;
}
到此這篇關(guān)于微信小程序?qū)崿F(xiàn)列表滾動頭部吸頂?shù)氖纠a的文章就介紹到這了,更多相關(guān)小程序列表滾動頭部吸頂內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
javascript Array.prototype.slice的使用示例
javascript Array.prototype.slice除了常見的從某個數(shù)組中抽取出新的數(shù)組外,它還有一些其他的用法,下面就為大家講這些妙用2013-11-11
HTA版JSMin(省略修飾語若干)基于javascript語言編寫
JSMin是一種很有用的ECMAScript代碼減肥工具,雖然它只是一種較為初級的工具,但用它來對付我自己編寫的大部分ECMAScript代碼效果都很不錯,而且在我這里也從未發(fā)生過減肥后代碼出錯之類的問題。2009-12-12
封裝了一個支持匿名函數(shù)的Javascript事件監(jiān)聽器
這篇文章主要介紹了支持匿名函數(shù)的Javascript事件監(jiān)聽封裝,需要的朋友可以參考下2014-06-06

