小程序 滾動到元素位置,設置元素置頂


小程序不支持,獲取窗口的滾動位置,比如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   }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM