小程序不支持,獲取窗口的滾動位置,比如window.pageYOffset、window.scrollY
當需要當界面滾動到元素位置時,設置元素固定,可以如下處理:
使用微信組件Scrollviewer
滾動時觸發,event.detail = {scrollLeft, scrollTop, scrollHeight, scrollWidth, deltaX, deltaY}
1 <ScrollView 2 className='evaluateParent' 3 scrollY 4 enableBackToTop 5 scrollAnchoring 6 onScroll={(event) => this.onPageScrollChanged(event.detail)} 7 style={{ height: wx.getSystemInfoSync().windowHeight }} 8 > 9 10 </ScrollView >
PS:滾動區域需要設置固定高度,高度通過wx.getSystemInfoSync().windowHeight來獲取
通過比較scrollTop與當前元素距離頁面頂部的值,來設置元素是否固定position = fixed
1 .messageTypeTabs_top { 2 position: fixed; 3 top: 0px; 4 left: 0px; 5 right: 0px; 6 z-index: 999; 7 }