Skip to content

qin.pageScrollTo(OBJECT) ​

将页面滚动到目标位置。可以指定滚动到具体的scrollTop数值,也可以指定滚动到某个元素的位置

平台差异说明 ​

H5微信小程序小红书小程序抖音小程序快手快应用
√√√√√

OBJECT 参数说明 ​

参数名类型必填说明
scrollTopNumber否滚动到页面的目标位置(单位 px)
selectorString否元素选择器,用于指定要滚动到的元素位置,H5 、微信小程序2.7.3+ 、支付宝小程序1.20.0+支持
durationNumber否滚动动画的时长,默认 300ms ,单位 ms
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

示例

js
qin.pageScrollTo({
  scrollTop: 0,
  duration: 300,
});
qin.pageScrollTo({
  scrollTop: 0,
  duration: 300,
});