文档管理中心
API参考快应用组件scroll-view(1110+)

scroll-view(1110+)

概述

可以滚动的视图区域。

使用限制

展开

限制条件

说明

适用终端

手机、平板、智慧屏、车机

适用区域

全球

子组件

支持。

属性

除了支持通用属性以外,还支持如下属性。

展开

名称

类型

默认值

是否必填

描述

scroll-direction

string

vertical

滚动方向,取值为vertical、horizontal和vertical_horizontal。

  • vertical:在flex-direction取值为column的情况下,当子视图区域的高度大于滚动视图的高度时,可以上下滚动滚动视图,让视图外的内容可见;当子视图区域的宽度大于滚动视图的宽度时,子视图区域的水平内容将被裁剪。
  • horizontal:在flex-direction取值为row的情况下,当子视图区域的宽度大于滚动视图的宽度时,可以左右滚动滚动视图,使视图外的内容可见;当子视图区域的高度大于滚动视图的高度时,子视图区域的垂直内容将被裁剪。
  • vertical_horizo​​ntal:在flex-direction取值为column的情况下,子视图区域不会被裁剪。

show-scrollbar

boolean

true

是否显示滚动条。

样式

支持通用样式

事件

除了支持通用事件以外,还支持如下事件。

展开

名称

参数

描述

scroll

{scrollX:Number, scrollY:Number, oldScrollX:Number, oldScrollY:Number}

滚动时触发。

  • scrollX:事件触发时,左侧距X轴方向的距离,单位为px。
  • scrollY:事件触发时,顶部距Y轴方向的距离,单位为px。
  • oldScrollX:滚动前,左侧距X轴方向的距离,单位为px。
  • oldScrollY:滚动前,顶部距Y轴方向的距离,单位为px。

scrollbegindrag

-

用户开始拖动滚动视图时触发。

scrollenddrag

-

用户停止拖动滚动视图时触发。

scrollstart

{scrollX:Number, scrollY:Number}

滚动视图开始滑动时触发。

scrollstop

{scrollX:Number, scrollY:Number}

滚动视图滑动结束时触发。

方法

展开

名称

参数

描述

scrollIntoView

{id}

滚动到指定id子组件的位置,设置向哪个方向滚动,然后滚动到哪个方向的元素。

scrollTo

{x: Number/String, y: Number/String, smooth: Boolean}

滚动到指定的 x、y 偏移量。

smooth:是否平滑滚动,可选,默认为true。

说明
  • x和y不能同时为空。
  • 如果只填x,则y轴不移动并水平滚动到指定的x;如果只填y,则x轴不移动并垂直滚动到指定的y。

示例代码

收起
自动换行
深色代码主题
复制
  1. <template>
  2. <!-- Only one root node is allowed in template. -->
  3. <div class="container">
  4. <text class="title">Vertical ScrollView</text>
  5. <scroll-view id="verticalScrollView" class="content" height="100px" flex-direction="column">
  6. <text>Some Information</text>
  7. <text>Some Information</text>
  8. <text>Some Information</text>
  9. <text>Some Information</text>
  10. <text>Some Information</text>
  11. <text>Some Information</text>
  12. <text>Some Information</text>
  13. <text>Some Information</text>
  14. </scroll-view>
  15. <text class="title">Horizontal ScrollView</text>
  16. <scroll-view id="horizontalScrollView" class="content" width="300px" scroll-direction="horizontal" flex-direction="row">
  17. <text>Some Information</text>
  18. <text>Some Information</text>
  19. <text>Some Information</text>
  20. <text>Some Information</text>
  21. <text>Some Information</text>
  22. <text>Some Information</text>
  23. <text>Some Information</text>
  24. <text>Some Information</text>
  25. </scroll-view>
  26. <text class="title">Vertical Horizontal ScrollView</text>
  27. <scroll-view id="verticalHorizontalScrollView" class="content" height="300px" scroll-direction="vertical_horizontal" flex-direction="column" onscrollbegindrag="onscrollbegindrag" onscrollenddrag="onscrollenddrag" onscrollstart="onscrollstart" onscrollstop="onscrollstop" onscroll="onscroll">
  28. <text id="here">Some Information</text>
  29. <text>Some Information</text>
  30. <text>Some Information</text>
  31. <text>Some Information</text>
  32. <text>Some Information</text>
  33. <text>Some Information</text>
  34. <text>Some Information</text>
  35. <text>Some Information</text>
  36. <div class="container" width="2000" height="2000">
  37. <image src="/Common/img/xmad.jpg"></image>
  38. </div>
  39. <select id="select">
  40. <option value="01"selected="false">Option 1</option>
  41. <option value="02"selected="false">Option 2</option>
  42. <option value="03"selected="false">Option 3</option>
  43. <option value="04"selected="false">Option 4</option>
  44. <option value="05"selected="true">Option 5</option>
  45. </select>
  46. <text id="here" style="color: #048004;">ScrollIntoView to here</text>
  47. <text>Some Information</text>
  48. <text>Some Information</text>
  49. <text>Some Information</text>
  50. </scroll-view>
  51. <input type="button" class="content" value="scrollIntoView" onclick=scrollIntoView></input>
  52. <input type="button" class="content" value="ScrollInto" onclick=scrollInto></input>
  53. </div>
  54. </template>
  55. <style>
  56. .container {
  57. flex-direction: column;
  58. }
  59. .title {
  60. color: #c71585;
  61. font-size: 40px;
  62. }
  63. .content {
  64. margin: 10px;
  65. border: 1px solid #000000;
  66. }
  67. </style>
  68. <script>
  69. module.exports = {
  70. data: {
  71. },
  72. onInit() {
  73. this.$page.setTitleBar({ text: 'SR337' })
  74. },
  75. scrollIntoView() {
  76. this.$element('verticalHorizontalScrollView').scrollIntoView({ id: "here" })
  77. },
  78. scrollInto() {
  79. this.$element('verticalHorizontalScrollView').scrollTo({ x: 300, y: 500 })
  80. }, onscroll(event) {
  81. console.log("onscroll x " + event.scrollX + " y " + event.scrollY);
  82. },
  83. onscrollbegindrag() {
  84. console.log("scrollbegindrag");
  85. },
  86. onscrollenddrag() {
  87. console.log("scrollenddrag");
  88. },
  89. onscrollstart(event) {
  90. console.log("onscrollstart x " + event.scrollX + " y " + event.scrollY);
  91. },
  92. onscrollstop(event) {
  93. console.log("onscrollstop x " + event.scrollX + " y " + event.scrollY);
  94. }
  95. }
  96. </script>

效果图如下:

版本更新说明

展开

版本

发布日期

描述

1110

2024-02-07

第一次正式发布。

在 API参考 中进行搜索
请输入您想要搜索的关键词