简体中文
将页面滚动到目标位置。可以指定滚动到具体的scrollTop数值,也可以指定滚动到某个元素的位置
| App | H5 | 微信小程序 | 支付宝小程序 | 百度小程序 | 抖音小程序、飞书小程序 | QQ小程序 | 华为快应用 | 360小程序 | 元服务 |
|---|---|---|---|---|---|---|---|---|---|
| √(nvue不支持) | √ | √ | √ | √ | √ | √ | √ | √ | √ |
| HarmonyOS |
|---|
| HBuilderX 4.23 |
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| scrollTop | Number | 否 | 滚动到页面的目标位置(单位px) |
| selector | String | 否 | 元素选择器,用于指定要滚动到的元素位置,App、H5、抖音小程序2.62.0+、微信小程序2.7.3+ 、支付宝小程序1.20.0+支持 |
| duration | Number | 否 | 滚动动画的时长,默认300,单位 ms |
| success | function | 否 | 接口调用成功的回调函数 |
| fail | function | 否 | 接口调用失败的回调函数 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
selector 语法
selector类似于 CSS 的选择器,但仅支持下列语法。
.a-class.another-class.the-parent > .the-child.the-ancestor .the-descendant.the-ancestor >>> .the-descendant#a-node, .some-other-nodesscroll-with-animation="true",详见示例
uni.pageScrollTo({
scrollTop: 0,
duration: 300
});