Skip to content

Scroll

pageScrollTo

TIP

The API usage is as follows: wx.pageScrollTo(Object object)

  • Functional description: Scroll the page to the target position.
  • Parameters and descriptions: Object object
PropertiesTypeDefault valueRequiredDescription
scrollTopnumber-YesScroll to the target position of the page, unit px
durationnumber300NoDuration of the scrolling animation, unit ms
successFunction-NoCallback function for successful interface call
failFunction-NoCallback function for failed interface call
completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)
  • Sample code:
js
wx.pageScrollTo({
  scrollTop: 0,
  duration: 300
})

ScrollViewContext

  • Functional description: Enhance the ScrollView instance, which can be obtained through the wx.createSelectorQuery method of NodesRef.node . It only takes effect after the scroll-view component turns on the enhanced attribute.
  • Attributes and descriptions
PropertiesTypeDescription
scrollEnabledbooleanScroll switch
bouncesbooleanSet the scroll boundary elasticity (only effective on iOS)
showScrollbarbooleanSet whether to display the scroll bar
pagingEnabledbooleanPaging slide switch
fastDecelerationbooleanSet the scroll deceleration rate (only valid on iOS)
decelerationDisabledbooleanCancel scroll inertia (only valid on iOS)
  • Sample code:
js
wx.createSelectorQuery()
  .select('#scrollview')
  .node()
  .exec((res) => {
    const scrollView = res[0].node;
    scrollView.scrollEnabled = false;
  })

.scrollIntoView

TIP

The API usage is as follows: ScrollViewContext.scrollIntoView(string selector, object ScrollIntoViewOptions)

  • Functional description: Scroll to the specified position.
  • Parameters and descriptions: string selector, element selector

.scrollTo

TIP

The API usage is as follows: ScrollViewContext.scrollTo(Object object)

  • Functional description: Scroll to the specified position.
  • Parameters and descriptions: Object object。
PropertiesTypeDefault valueRequiredDescription
topnumber-NoTop distance
leftnumber-NoLeft border distance
velocitynumber-NoInitial speed (only valid on iOS)
durationnumber-NoScroll animation duration (only valid on iOS)
animatednumber-NoWhether to enable scroll animation