1. 程式人生 > 其它 >uni-app監聽頁面滾動條 view 吸頂

uni-app監聽頁面滾動條 view 吸頂

技術標籤:uni-appuni-app

根據頁面 滾動到一定位置後 將導航吸頂
在這裡插入圖片描述
導航上面 兩個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; } }