小程序將頁面滾動到目標位置wx.pageScrollTo
wx.pageScrollTo(Object object)
將頁面滾動到目標位置,支持選擇器和滾動距離兩種方式定位
參數
Object object
屬性 類型 默認值 必填 說明 最低版本
scrollTop number 否 滾動到頁面的目標位置,單位 px
duration number 300 否 滾動動畫的時長,單位 ms
selector string 否 選擇器 2.7.3
offsetTop number 否 偏移距離,需要和 selector 參數搭配使用,可以滾動到 selector 加偏移距離的位置,單位 px 2.23.1
success function 否 接口調用成功的回調函數
fail function 否 接口調用失敗的回調函數
complete function 否 接口調用結束的回調函數(調用成功、失敗都會執(zhí)行)
selector 語法
selector類似于 CSS 的選擇器,但僅支持下列語法。
ID選擇器:#the-id
class選擇器(可以連續(xù)指定多個):.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
})
- 小程序開始下拉刷新
- 開始下拉刷新。調用后觸發(fā)下拉刷新動畫,效果與用戶手動下拉刷新一致。
- 04-06 關注:0