All Products
Search
Document Center

Mobile Platform as a Service:Scroll

Last Updated:Feb 03, 2021

my.pageScrollTo

Scroll to the target position of the page.

Note:
  • This interface is only supported in mPaaS 10.1.32 and later versions.
  • The scrollTop has a higher priority than selector.
  • When my.pageScrollTo is used to jump to the top of the Mini Program, the scrollTop value must be set as a number greater than 0 to make jump possible.

Parameters

Parameter
Type
Default value
Required
Description
scrollTop
Number
-
No
Scroll to the target position of the page, in px. When my.pageScrollTo is used to jump to the top of the Mini Program, the scrollTop value must be set as a number greater than 0 to make jump possible.
duration
Number
0
No
Duration of scroll animation, in ms.
selector
String
-
No
Selector
success
Function
-
No
Callback function upon call success.
fail
Function
-
No
Callback function upon call failure.
complete
Function
-
No
Callback function upon call completion (to be executed upon either call success or failure).

Syntax of selector

When the selector parameter is passed in, the framework executes document.querySelector(selector) to select the target node.

Code example

  1. <!-- API-DEMO page/API/page-scroll-to/page-scroll-to.axml-->
  2. <view class="page">
  3. <view class="page-description">API for scrolling page</view>
  4. <view class="page-section">
  5. <view class="page-section-title">
  6. my.pageScrollTo
  7. </view>
  8. <view class="page-section-demo">
  9. <input type="text" placeholder="key" name="key" value="{{scrollTop}}" onInput="scrollTopChange"></input>
  10. </view>
  11. <view class="page-section-btns">
  12. <view onTap="scrollTo">Scroll page</view>
  13. </view>
  14. </view>
  15. <view style="height:1000px"/>
  16. </view>
  1. // API-DEMO page/API/page-scroll-to/page-scroll-to.js
  2. Page({
  3. data: {
  4. scrollTop: 0,
  5. },
  6. scrollTopChange(e) {
  7. this.setData({
  8. scrollTop: e.detail.value,
  9. });
  10. },
  11. onPageScroll({ scrollTop }) {
  12. console.log('onPageScroll', scrollTop);
  13. },
  14. scrollTo() {
  15. my.pageScrollTo({
  16. scrollTop: parseInt(this.data.scrollTop),
  17. duration: 300,
  18. });
  19. },
  20. });