Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program API scrolling


May 19, 2021 WeChat Mini Program Development Document


Table of contents


wx.pageScrollTo(Object object)

Base library 1.4.0 starts to support, and low versions need to be compatible.

Scroll the page to the destination, supporting both the selector and the scroll distance

Parameters

Object object

Property Type The default Required Description The lowest version
scrollTop number Whether Scroll to the target location of the page in px
duration number 300 Whether The length of the scroll animation, in ms
selector string Whether Selector 2.7.3
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

Selector syntax

Selector is similar to the CSS selector, but only supports the following syntax.

  • ID selector: #the-id
  • class selector (can specify more than one in a row): .a-class.another-class
  • Child Element Selector: .the-parent and .the-child
  • Descendant selector: .the-ancestor .the-descendant
  • Descendant selectors across custom components: .the-ancestor and .the-descendant
  • The intersection of multiple selectors: #a-node, .some-other-nodes

The sample code

wx.pageScrollTo({
  scrollTop: 0,
  duration: 300
})