pageScrollTo
该 API 使用方法为 wx.pageScrollTo(Object object)
功能说明:将页面滚动到目标位置。
参数及说明:Object object。
属性 | 类型 | 默认值 | 必填 | 说明 |
scrollTop | number | - | 是 | 滚动到页面的目标位置,单位 px |
duration | number | 300 | 否 | 滚动动画的时长,单位 ms |
success | function | - | 否 | 接口调用成功的回调函数 |
fail | function | - | 否 | 接口调用失败的回调函数 |
complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
示例代码
wx.pageScrollTo({scrollTop: 0,duration: 300})
ScrollViewContext
功能说明:增强 ScrollView 实例,可通过 wx.createSelectorQuery 的 NodesRef.node 方法获取。仅在 scroll-view 组件开启 enhanced 属性后生效。
属性及说明
属性 | 类型 | 说明 |
scrollEnabled | boolean | 滚动开关 |
bounces | boolean | 设置滚动边界弹性 (暂不支持) |
showScrollbar | boolean | 设置是否显示滚动条 |
pagingEnabled | boolean | 分页滑动开关 |
fastDeceleration | boolean | 设置滚动减速速率 |
decelerationDisabled | boolean | 取消滚动惯性 (仅在 iOS 下生效) |
示例代码:
wx.createSelectorQuery().select('#scrollview').node().exec((res) => {const scrollView = res[0].node;scrollView.scrollEnabled = false;})
.scrollIntoView
该 方法 使用方式为 ScrollViewContext.scrollIntoView(string selector, object ScrollIntoViewOptions)
功能说明:滚动至指定位置。
参数及说明:string selector,元素选择器。
.scrollTo
该 方法 使用方式为 ScrollViewContext.scrollTo(Object object)
功能描述:滚动至指定位置。
参数及说明:Object object。
属性 | 类型 | 默认值 | 必填 | 说明 |
top | number | - | 否 | 顶部距离 |
left | number | - | 否 | 左边界距离 |
velocity | number | - | 否 | 初始速度 |
duration | number | - | 否 | 滚动动画时长 |
animated | boolean | - | 否 | 是否启用滚动动画 |