uni-app監聽頁面滾動條 view 吸頂
阿新 • • 發佈:2021-01-31
根據頁面 滾動到一定位置後 將導航吸頂
導航上面 兩個view的高度要獲取到
<view id='search_model'>搜尋</view>
<view id='headerPanel'>banner</view>
<view :style="{position:scrollTop<bannerHeight?'absolute':'fixed'}">導航</view>
export default {
data(){
return{
bannerHeight : 0,
scrollTop:0
}
},
onLoad(){
const query = uni.createSelectorQuery();
query.select('#headerPanel').boundingClientRect(data => {
this.bannerHeight = data.height;
}).exec();
query.select('#search_model').boundingClientRect(data => {
this.bannerHeight = this.bannerHeight+data. height;
}).exec();
},
//監聽滾動條
onPageScroll(e){
this.scrollTop = e.scrollTop;
}
}