worklet.scrollViewContext.scrollTo

worklet.scrollViewContext.scrollTo(Object object)

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

小程序插件:不支持

相关文档: worklet 动画NodesRef.ref

功能描述

滚动至指定位置

参数

Object object

属性 类型 默认值 必填 说明
top number 顶部距离
left number 左边界距离
duration number 滚动动画时长
animated boolean 是否启用滚动动画
easingFunction string 动画曲线

示例代码

const { scrollViewContext } = wx.workelt

Page {
  onLoad() {
    this.scrollRef = shared()
    this.createSelectorQuery().select('.scrollable').ref(function(res) {
      this.scrollRef.value = res.ref
    }).exec()
  },

  onTap() {
    'worklet'
    scrollViewContext.scrollTo(this.scrollRef.value, {
      top: 200,
      duration: 2000,
      animated: true,
      easingFunction: 'ease'
    })
  }
}
posted on 2025-01-02 09:29  AtlasLapetos  阅读(9)  评论(0)    收藏  举报