<scroll-view>
Basic scrolling component supporting both horizontal and vertical scrolling. When its content area is larger than its visible area, it allows users to scroll to reveal more content.
<scroll-view>
supports both horizontal and vertical scrolling, implemented through the scroll-orientation
properties.
<scroll-view>
always uses the linear layout, and the layout direction is determined by the scroll-orientation
attributes.
Use event callbacks such as bindscroll
, bindscrolltoupper
, and bindscrolltolower
to monitor changes in scroll progress.
As a child node of <scroll-view>
, you can set the sticky
attribute making the child node remain at a certain distance from the top of the <scroll-view>
and not continue scrolling with the content.
sticky
can only be set for direct child nodes of <scroll-view>
. On Android only, you need to add the flatten={false}
attribute to sticky
nodes.
The direct child nodes of <scroll-view>
only support linear
and sticky
. If you need more complex layouts, such as child nodes adapting to expand, it is recommended to provide a single child view to the <scroll-view>
and implement more robust CSS capabilities within that single child node.
Attribute names and values describe the behavior and appearance of the component.
scroll-orientation
set scroll orientation for the scrollable container.
值 | 说明 |
---|---|
vertical | Child nodes are arranged vertically, causing <scroll-view> itself to scroll vertically |
horizontal | Child nodes are arranged horizontally, causing <scroll-view> itself to scroll horizontally |
enable-scroll
Sets whether to allow gesture dragging to scroll. Supports dynamic switching and takes effect on the next gesture. When scrolling is disabled, the user cannot scroll manually.
Value | Description |
---|---|
true | User gestures can trigger scrolling |
false | User gestures cannot trigger scrolling but scrolling methods (e.g., scrollTo ) can still initiate scrolling |
initial-scroll-offset
Sets the absolute content offset distance during initial rendering (different from the offset
concept in the scrollTo
method). The horizontal or vertical direction is determined by scroll-orientation
, and it only takes effect during the first render
execution, not responding to subsequent changes.
Cannot be used simultaneously with initial-scroll-offset/to-index
as they will cover each other.
initial-scroll-to-index
Sets the child node to be positioned during initial rendering, only taking effect during the first render
execution and not responding to subsequent changes.
Cannot be used simultaneously with initial-scroll-offset/to-index
as they will cover each other.
If the index
is invalid (e.g., negative or exceeds the number of child nodes), the setting is ineffective.
bounces
iOS onlyEnables edge bounce effect.
upper-threshold
Sets a scroll threshold (unit: px
), indicating how far from the top or left before triggering the scrolltoupper
event.
lower-threshold
Sets a scroll threshold, indicating how far from the bottom or right before triggering the scrolltolower
event.
scroll-bar-enable
Enables the scrollbar, supporting dynamic switching.
Android only Only vertical scrolling has scrollbars. iOS only Supports both vertical and horizontal scrollbars.
Frontend can bind corresponding event callbacks to components to monitor their runtime behavior.
scroll
Triggered during scrolling (whether animated or not).
If there is a bounce (bounces={true}
), scrollLeft
and scrollTop
may be
negative during the bounce.
scrolltoupper
Triggered when the defined upperThreshold
area intersecting the visible area at the top or left.
scrolltolower
Triggered when the defined lowerThreshold
area intersects the visible area at the bottom or right.
scrollend
Triggered when scrolling ends.
contentsizechanged
Triggered when the content area comprised of direct child nodes changes in width or height. This event triggers after the <scroll-view>
content completes layout. If updating <scroll-view>
child nodes, call updated scrolling methods like scrollTo
in this event.
Frontend can execute component methods through the SelectorQuery API, using the following methods:
scrollTo
Positions the <scroll-view>
content to a specific location, using either the child node index index
or an absolute offset offset
. For the offset
parameter, positive is right, negative is left; in RTL mode, positive-negative reverses, positive is left, negative is right.
autoScroll
Triggers automatic scrolling. If the rate
is too small, it may not scroll. Upon reaching the boundary, autoScroll
will stop automatically. If the user drags in the opposite direction to a certain position and releases, autoScroll
will not re-trigger auto-scrolling.
scrollIntoView
Scrolls the <scroll-view>
to the specified child node. This method is bound to any (direct/indirect) child node of <scroll-view>
, not <scroll-view>
itself.
scrollBy
Scrolls by the distance based on existing offsets, unit px
.
<scroll-view>
creates all of its child nodes at once, potentially causing severe first-screen load times. Use exposure events to drive it to create only visible child nodes.
<scroll-view>
lacks any reuse mechanism. If content is too extensive, it may consume an exceptionally large amount of memory, possibly causing OOM and other stability problems.
For data exceeding three screens, use <list>
to optimize performance, or simulate <VisualizedList>
logic based on exposure events.
LCD tables only load in the browser