目录

scroll-view

可滚动视图区域,相当于 web 中设置了 overflow 属性的 div 元素。

起始版本:1.0.0

约束与限制

使用竖向滚动时,需要通过 CSS 设置 height,给scroll-view一个固定高度。组件属性的长度单位默认为px。

属性

名称

类型

默认值

必填

描述

scroll-x

boolean

false

否

允许横向滚动。

scroll-y

boolean

false

否

允许纵向滚动。

upper-threshold

number/string

50

否

距顶部/左边多远时,触发 scrolltoupper 事件。

lower-threshold

number/string

50

否

距底部/右边多远时,触发 scrolltolower 事件。

scroll-top

number/string

-

否

设置竖向滚动条位置。

scroll-left

number/string

-

否

设置横向滚动条位置。

scroll-into-view

string

-

否

值应为某子元素id(id不能以数字开头)。设置哪个方向可滚动,则在哪个方向滚动到该元素。

scroll-with-animation

boolean

false

否

在设置滚动条位置时使用动画过渡。

show-scrollbar

boolean

true

否

滚动条显隐控制。

refresher-enabled

boolean

false

否

开启自定义下拉刷新。

refresher-threshold

number

45

否

设置自定义下拉刷新阈值。

refresher-default-style

string

"black"

否

设置自定义下拉刷新默认样式,支持设置 black | white | none, none 表示不使用默认样式。

refresher-background

string

-

否

设置自定义下拉刷新区域背景颜色,默认为透明。

refresher-triggered

boolean

false

否

设置当前下拉刷新状态,true 表示下拉刷新已经被触发,false 表示下拉刷新未被触发。

事件

名称

参数

描述

bindscrolltoupper

event

滚动到顶部/左边时触发。

bindscrolltolower

event

滚动到底部/右边时触发。

bindscroll

event

滚动时触发,event.detail = {scrollLeft, scrollTop, scrollHeight, scrollWidth, deltaX, deltaY}。

bindrefresherpulling

eventhandle

自定义下拉刷新控件被下拉。

bindrefresherrefresh

eventhandle

自定义下拉刷新被触发。

bindrefresherrestore

eventhandle

自定义下拉刷新被复位。

bindrefresherabort

eventhandle

自定义下拉刷新被中止。

示例

hxml文件

<scroll-view
  scroll-y="{{scrollY}}"
  style="height: 520px"
  upper-threshold="50"
  lower-threshold="30px"
  bindscrolltoupper="upper"
  bindscrolltolower="lower"
>
  <view id="demo1" class="scroll-view-item demo-text-1">1</view>
  <view id="demo2" class="scroll-view-item demo-text-2">2</view>
  <view id="demo3" class="scroll-view-item demo-text-3">3</view>
</scroll-view>

js文件

Page({
  data: {
    scrollY: true,
  },
  upper(e) {
    console.log("触发upper函数");
  },
  lower(e) {
    console.log("触发lower函数");
  },
});