HomeDocs
Skip to main content

dlt.pageScrollTo

Introduction

Scrolls the page to a specified position.

Parameters

Object object

PropertyTypeDefaultRequiredDescription
scrollTopnumberNoThe target scroll position of the page (in pixels).
selectorstringNoA selector.
durationnumber300NoThe duration of the scroll animation (in milliseconds).
successfunctionNoCallback function called when the interface is successfully invoked.
failfunctionNoCallback function called when the interface invocation fails.
completefunctionNoCallback function called when the interface invocation is complete (called whether the invocation is successful or not).

object.success Callback Function

Parameters

Object res

PropertyTypeDescription
errMsgstring"ok" - Success

object.fail Callback Function

Parameters

Object res

PropertyTypeDescription
errMsgstring-1 - Failure

Selector Syntax

The selector is similar to CSS selectors but supports only the following syntax.

  • ID selector: #the-id
  • Class selector (multiple can be specified): .a-class.another-class
  • Child element selector: .the-parent > .the-child
  • Descendant selector: .the-ancestor .the-descendant
  • Cross-component descendant selector: .the-ancestor >>> .the-descendant
  • Union of multiple selectors: #a-node, .some-other-nodes

Note: When using a selector to specify the scroll target, do not set scrollTop; it will be based on the selector.

Sample Code

// pages/index/index.js
Page({
pageScrollTo() {
dlt.pageScrollTo({
scrollTop: 0,
duration: 1000,
success: function () {
console.log('success');
},
fail: function () {
console.log('fail');
},
complete: function () {
console.log('complete');
},
});
},
});

In the provided sample code, the pageScrollTo function is called to scroll the page to the top (scrollTop: 0) with a duration of 1000 milliseconds. Callback functions are provided for success, failure, and completion. Adjust the scrollTop value and duration as needed for your use case.

Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.