开发者社区
社区提问意见反馈
开发者钉组织
扫描二维码
加入支付宝开发者钉组织
开发 > 组件 > 视图容器 > scroll-view 可滚动视图区域
收藏
订阅更新
我的文档
设置
简介
可滚动视图区域。scroll-view 滚动条可以全局禁用滚动,但是无法禁用 scroll-view 中的滚动距离展示。
使用限制
使用竖向滚动时,需要指定固定高度,可通过 acss 设置 height
在滚动 scroll-view 时会阻止页面回弹,所以在 scroll-view 中滚动,无法触发 onpulldownrefresh 下拉刷新功能。
scroll-view 不支持 scroll-x=truescroll-y=true 同时生效,只能用一个。可以使用 view 设置 disable-scroll 为 true 禁止滑动。
scroll-view 满屏时,无法滑动页面,会导致导航栏滑动透明失效。可通过 my.setnavigationbar 设置导航栏样式:导航栏标题、导航栏背景色、导航栏底部边框颜色、导航栏左上角 logo 图片。
scroll-view 组件不支持自定义下拉刷新。
scroll-view 组件的滚动条默认隐藏,仅在滑动时展示。
scroll-view 组件在 ios 下不支持自定义修改,在 android 下允许通过 ::-webkit-scrollbar 自定义滚动条样式。
扫码体验

使用
在线示例

属性说明
表格中 “-” 代表支持。
属性
类型
描述
webview 兼容性
native 兼容性
class
string
外部样式名。
-
-
style
string
内联样式名。
-
-
scroll-x
boolean
允许横向滚动。 默认值: false
-
-
scroll-y
boolean
允许纵向滚动。 默认值: false
-
-
upper-threshold
number
距顶部/左边多远时(单位 px),触发 scrolltoupper
事件。 默认值: 50
-
-
lower-threshold
number
距底部/右边多远时(单位 px),触发 scrolltolower
事件。 默认值: 50
-
-
scroll-top
number
设置竖向滚动条位置。
-
-
scroll-left
number
设置横向滚动条位置。
-
-
scroll-into-view
string
滚动到子元素,值应为某子元素的 id。当滚动到该元素时,元素顶部对齐滚动区域顶部。 说明:scroll-into-view
的优先级高于 scroll-top

-
暂不支持
scroll-with-animation
boolean
在设置滚动条位置时使用动画过渡。 默认值: false
-
-
scroll-animation-duration
number
scroll-with-animation
设置为 true 时,可以设置 scroll-animation-duration
来控制动画的执行时间,单位 ms。
基础库 1.9.0
-
enable-back-to-top
boolean
当点击 ios 顶部状态栏或者双击 android 标题栏时,滚动条返回顶部,只支持竖向。 默认值: false
基础库 1.11.0
-
trap-scroll
boolean
纵向滚动时,当滚动到顶部或底部时,强制禁止触发页面滚动,仍然只触发 scroll-view 自身的滚动。 默认值: false
基础库 1.11.2
-
onscrolltoupper
eventhandle
滚动到顶部/左边,会触发 scrolltoupper
事件。
-
-
onscrolltolower
eventhandle
滚动到底部/右边,会触发 scrolltolower
事件。
-
-
onscroll
eventhandle
滚动时触发,event.detail = {scrollleft, scrolltop, scrollheight, scrollwidth}

-
-
ontouchstart
eventhandle
触摸动作开始。
基础库 1.15.0
-
ontouchmove
eventhandle
触摸后移动。
基础库 1.15.0
-
ontouchend
eventhandle
触摸动作结束。
基础库 1.15.0
-
ontouchcancel
eventhandle
触摸动作被打断,如来电提醒、弹窗。
基础库 1.15.0
-
disable-lower-scroll
string
发生滚动前,对滚动方向进行判断,当方向是顶部/左边时,如果值为 always
将始终禁止滚动,如果值为 out-of-bounds
且当前已经滚动到顶部/左边,禁止滚动。
基础库 2.6.2
-
disable-upper-scroll
string
发生滚动前,对滚动方向进行判断,当方向是底部/右边时,如果值为 always
将始终禁止滚动,如果值为 out-of-bounds
且当前已经滚动到底部/右边,禁止滚动。
基础库 2.6.2
-
faq
为何 scroll-view 在 popup 扩展组件中无法滑动?
popup 组件上加上 disablescroll={{false}} 属性才能滑动。
为何使用 swiper 嵌套 scroll-view,scroll-view 无法滑动?
swiper 和 scroll-view 均为滑动组件,如果必须使用,建议不做嵌套或者让 scroll-view 阻止 touch 事件冒泡即可:catchtouchstart、catchtouchmove。
如何监听 scroll-view 滚动到底部?
可以直接在 onscroll 方法中进行处理,使用 onscrolltolower 监听 scroll-view 的滚动高度来进行判断是否滑动到了底部。 scrollheight 是 scroll-view 里面所有 view 的高度和,scrolltop 是滚动的值; scrolltop 的值等于 scrollheight-scroll-view 视图的高度。
为何在页面有蒙层的情况下,外层滑动到底部,会导致蒙层也能滑动?
在外层 scroll-view 添加属性 trap-scroll。
为什么 onscrolltoupper 和 onscrolltolower 事件同时被触发,且触发了多次?
因为滚动时同时满足了距顶部 ${upper-threshold}px 内,距底部 ${lower-threshold}px 内,所以会同时触发 onscrolltoupper 和 onscrolltolower 事件。可以通过调整参数 upper-threshold 和 lower-threshold 避免一直处在触发区间来解决。
相关文档
view 视图容器
my.setnavigationbar
popup 弹出菜单
内容没有解决您的问题?您还可以前往 或 寻求帮助
凯发k8官方网娱乐官方 copyright © 2022 支付宝(杭州)信息技术有限公司  | icp证浙b2-20160559
该文档对你是否有帮助?
当前页面目录
网站地图