# wx.pageScrollTo(Object object)
Start from base library version 1.4.0. Please remaining backward compatible.
with Promise style call: Supported
Need page permissions: Mini Programs cannot call this interface from a plugin page, and plugins cannot call the interface from the plugins page
Mini Program plugin: Support, need to Mini Program base library version no less than 2.1.0
When used in Mini Programs plug-ins, can only be called from the page of the current plug-in
WeChat Windows edition: Support
WeChat Mac edition: Support
Scroll the page to the target location, support selection and scrolling distance positioning in two ways
# parameter
# Object object
attribute | type | Default values | Required | Introductions | Minimum version |
---|---|---|---|---|---|
scrollTop | number | no | Scroll to the target location on the page, unit px | ||
duration | number | 300 | no | Length of scrolling animation, in units ms | |
selector | string | no | Selector | 2.7.3 | |
success | function | no | Interface calls the successful callback function | ||
fail | function | no | Interface calls failed callback functions | ||
complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) |
# selector grammar
Selectors are similar to CSS But only the following syntax is supported.
- ID selector:#the-id
- Class selector (you can specify more than one in a row):. a-class.another-class
- Child element selector:. The-parent > .the-child
- Descendant selector:. The-ancester .the-descendant
- Descendant selector across custom components:. The-ancester >>> .the-descendant
- Union of multiple selectors:#a-node, .some-other-nodes
# sample code
wx.pageScrollTo({
scrollTop: 0,
duration: 300
})