微信小程序?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的面向?qū)ο蟮奶匦詫崿F(xiàn)限制試用期
Javascript是一種面向?qū)ο蟮哪_本語言,其也具有面向?qū)ο蟮娜筇匦裕墙裉煳覀儾辉敿毜闹v解javascript的面向?qū)ο筇匦?,今天我們簡單的了解一下javascript的面向?qū)ο筇匦裕缓髮W習一下怎樣實現(xiàn)試用期的限制!2011-08-08
js獲取UserControl內(nèi)容為拼html時提供方便
js獲取UserControl內(nèi)容時無法測試通過,原來是繼承了Page 然后使用VerifyRenderingInServerForm驗證2014-11-11
javascript實現(xiàn)的字符串與十六進制表示字符串相互轉(zhuǎn)換方法
這篇文章主要介紹了javascript實現(xiàn)的字符串與十六進制表示字符串相互轉(zhuǎn)換方法,涉及javascript字符串轉(zhuǎn)換的相關(guān)技巧,在防止SQL注入和XSS中具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07
利用JavaScript實現(xiàn)防抖節(jié)流函數(shù)的示例代碼
在開發(fā)中我們經(jīng)常會遇到一些高頻操作,比如:鼠標移動,滑動窗口,鍵盤輸入等等,節(jié)流和防抖就是對此類事件進行優(yōu)化,降低觸發(fā)的頻率,以達到提高性能的目的。本文就教大家如何實現(xiàn)一個讓面試官拍大腿的防抖節(jié)流函數(shù),需要的可以參考一下2022-08-08
JavaScript編寫帶旋轉(zhuǎn)+線條干擾的驗證碼腳本實例
除了普通的可點擊更換的四位驗證碼實現(xiàn),我們這里還展示了更進一步的JavaScript編寫帶旋轉(zhuǎn)+線條干擾的驗證碼腳本實例,需要的朋友可以參考下2016-05-05

