has.pageScrollTo(Object object)
Scrolls the page to the target position.
Since: 1.0.0
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| scrollTop | number | - | No | Scrolling target position on a page, in pixels. Either this parameter or the selector parameter must be specified. If both are specified, scrollTop is used preferentially. |
| duration | number | 300 | No | Duration of the scrolling animation, in milliseconds. |
| selector | string | - | No | Selector. |
| offsetTop | number | - | No | Offset distance (in px). This parameter must be used together with the selector parameter to adjust the final scroll position by adding/subtracting the specified offset from the element's position identified by selector. |
| success | function | - | No | Callback triggered when the API call is successful. |
| fail | function | - | No | Callback triggered when the API call fails. |
| complete | function | - | No | Callback triggered when the API call is complete, regardless of success or failure. |
Selector syntax
The selector is similar to a CSS selector, but only the following syntax is supported.
Class selector (multiple selectors can be specified consecutively): .a-class.another-class
Descendant selector across custom components: .the-ancestor >>> .the-descendant
Error code information
| Error Code | Error Message |
|---|---|
| 102 | Parameter error. Possible causes: check type is invalid. |
| 30001401 | pageScrollTo error. Possible causes: page scroll to has no target. For details, see Webview Error Codes. |
Example:
has.pageScrollTo({
scrollTop: 0,
duration: 300
}); ScrollViewContext instance, which can be obtained through the NodesRef.node method of has.createSelectorQuery. This method takes effect only when the enhanced attribute is enabled for the scroll-view component.
Since: 1.0.23
Attributes
| Name | Type | Default Value | Description |
|---|---|---|---|
| scrollEnabled | boolean | true | Whether scrolling is enabled. |
| showScrollbar | boolean | true | Whether to display the scrollbar. |
| pagingEnabled | boolean | false | Whether to enable pagination scrolling. |
Example:
has.createSelectorQuery()
.select('#scrollview')
.node()
.exec((res) => {
const scrollView = res[0].node;
scrollView.scrollEnabled = false;
}); ScrollViewContext.triggerRefresh(Object object)
Starts pull-to-refresh.
Since: 1.0.23
Parameters
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| duration | number | 300 | No | Animation duration, in milliseconds. |
| easingFunction | string | ease | No | Animation curve. The following animation curves are supported: - ease: The animation starts and ends slowly. - linear: The animation speed changes linearly. - ease-in: The animation starts slowly and then speeds up. - ease-out: The animation starts fast and then slows down. - ease-in-out: The animation starts fast, slows down, and then speeds up again. |
Error code information
| Error Code | Error Message |
|---|---|
| 102 | Parameter error. Possible causes: check type is invalid. |
Example:
has.createSelectorQuery().select('#id').node(function (res) {
const ctx = res.node;
console.info('ctx = ', ctx);
ctx.triggerRefresh({
duration: 500,
easingFunction: 'ease'
});
}).exec(); ScrollViewContext.closeRefresh()
Closes pull-to-refresh.
Since: 1.0.23
Example:
has.createSelectorQuery().select('#id').node(function (res) {
const ctx = res.node;
console.info('ctx = ', ctx);
ctx.closeRefresh();
}).exec(); ScrollViewContext.scrollTo(Object object)
Scrolls to a specified position.
Since: 1.0.23
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| top | number | No | Top distance, in pixels. |
| left | number | No | Left boundary distance, in pixels. |
| duration | number | No | Scrolling animation duration, in milliseconds. |
| animated | boolean | No | Whether to enable the scrolling animation. |
Error code information
| Error Code | Error Message |
|---|---|
| 102 | Parameter error. Possible causes: check type is invalid. |
Example:
has.createSelectorQuery().select('#id').node(function (res) {
const ctx = res.node;
console.info('ctx = ', ctx);
ctx.scrollTo({
top: 50,
duration: 1000,
animated: true
});
}).exec(); ScrollViewContext.scrollIntoView(string selector, Object ScrollIntoViewOptions)
Scrolls to a specified view.
Since: 1.0.23
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| selector | string | Yes | Element selector ID. |
| ScrollIntoViewOptions | Object | No | ScrollIntoViewOptions object. |
ScrollIntoViewOptions
The input parameter is an object containing the following fields.
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| offset | number | 0 | No | Extra offset when jumping to the target node, in px. |
| animated | boolean | true | No | Whether to enable the scrolling animation. |
Error code information
| Error Code | Error Message |
|---|---|
| 102 | Parameter error. Possible causes: check type is invalid. |
Example:
has.createSelectorQuery().select('#id').node(function (res) {
const ctx = res.node;
console.info('ctx = ', ctx);
ctx.scrollIntoView('viewA', {
offset: 0,
animated: true
});
}).exec();