Article directory
WeChat applet
hit bottom
/** * 上拉触底事件 */ onReachBottom() { console.log('上拉触底事件触发'); }
onReachBottom
Listen to the user's pull-up bottoming event.
The trigger distance can be set in theapp.json
optionswindow
or page configurationonReachBottomDistance
.
During the sliding period within the trigger distance, this event will only be triggered once.
peaking event
onPageScroll({ scrollTop }) { console.log('页面滑动触发'); if(scrollTop === 0) conosle.log('触顶'); }
onPageScroll(Object object)
Listen for user sliding page events.
The property of the parameterObject object
isscrollTop
; the type isNumber
, indicating the scrolling distance of the page in the vertical direction, and the unit ispx
.
Please define this method in only when you need itpage
, don't define empty method. To reduce the impact of unnecessary event dispatch on the logic layer communication of the rendering layer.
Please avoidonPageScroll
performing operations that cause logic layer-rendering layer communication too frequently insetData
. Especially if a large amount of data is transmitted each time, it will affect the time-consuming communication.
sleepApp
hit bottom
onReachBottom() { console.log('触底'); }
The event of scrolling to the bottom of the page (not
scroll-view
scrolling to the bottom), which is often used to pull down the next page of data.
onReachBottom
You canpages.json
define the trigger distance of the bottom of the specific page inonReachBottomDistance
. For example, if it is set , the event will be triggered when50
the page is scrolled to the bottom .50px
onReachBottom
hit the top
onPageScroll({ scrollTop }) { console.log('监听页面滚动'); if (scrollTop === 0) console.log('页面触顶'); }
scrollTop
ReturnsNumber
the type, the distance that the page has scrolled in the vertical direction, and the unit ispx
.
onPageScroll
Do not write complex interactionsjs
, such as frequently modifying pages. Because this life cycle is triggered at the rendering layer, at the non-h5
end,js
it is executed at the logic layer, and the communication between the two layers is lossy. If the data exchange between the two layers is frequently triggered during the scrolling process, it may cause lag.
If you want to realize the transparent gradient of the title bar when scrolling, you can configure the following inApp
and below . If some elements need to be fixed by the scroll ceiling, it is recommended to use the sticky layout, refer to the plug-in market. There are also other ceiling plug-ins in the plug-in market, but their performance is not good, so you can search for them yourself when you need them. In , WeChat applet, , you can also use monitor scrolling; in , you can use monitor scrolling. Not available on , which would result in failure to prevent the default return.H5
pages.json
titleNView
type
transparent
css
js
App
H5
wxs
app-nvue
bindingx
onBackPress
async
Application Scenario
This application scenario will be used more when customizing the tabBar , because when customizing the tabBar, the corresponding
tabBar
page will not trigger bottoming and scrolling events. At this time,tabBar
the bottoming and scrolling events of the stored parent page will be triggered, which can be borrowed toref
implement the function call of the correspondingtabBar
page.