How to use onPageScroll in WeChat Mini Programs component

how to use onPageScroll, in WeChat Mini Programs Custom component I set the value in properties in the component when I need onPageScroll.


has gone through the latest development documentation, and there are a few issues that need to be confirmed.
1 according to your problem, it is preliminarily determined that onPageScroll is not triggered in the component, it may be that this event is only registered in Page
if this is the case, then consider to achieve it in the component through other methods.
2 visual observation that your requirement is to do a component, which is universal to the page, is displayed when the scrolling value of the current page is greater than 600, and click to make the page scroll to the top correctly.
3 then consider using WXML node information API . After just doing it, it should be able to meet the needs of your component. Get the scrolltop value of the corresponding page in the component to execute the corresponding method.


Brother, where is res, let top=res.scrollTop;? According to the way you write it, res is the parameter value passed by onPageScroll, so it should be onPageScoll (res) {.}


onPageScroll(scrollTop){
    console.log(scrollTop)
}

Note that scroll-view affects the hook function above.

Menu