微信小程序API 滚动

2020-07-24 13:47 更新

wx.pageScrollTo(Object object)

基础库 1.4.0 开始支持,低版本需做兼容处理

将页面滚动到目标位置,支持选择器和滚动距离两种方式定位

参数

Object object

属性类型默认值必填说明最低版本
scrollTopnumber滚动到页面的目标位置,单位 px
durationnumber300滚动动画的时长,单位 ms
selectorstring选择器2.7.3
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

selector 语法

selector类似于 CSS 的选择器,但仅支持下列语法。

  • ID选择器:#the-id
  • class选择器(可以连续指定多个):.a-class.another-class
  • 子元素选择器:.the-parent > .the-child
  • 后代选择器:.the-ancestor .the-descendant
  • 跨自定义组件的后代选择器:.the-ancestor >>> .the-descendant
  • 多选择器的并集:#a-node, .some-other-nodes

示例代码

wx.pageScrollTo({
  scrollTop: 0,
  duration: 300
})


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号