The scrollable view area.
Attributes
Attribute | Type | Default value | Description | Minimum version |
class | String | - | External style name | - |
style | String | - | Inline style name | - |
scroll-x | Boolean | false | Allow horizontal scrolling | - |
scroll-y | Boolean | false | Allow vertical scrolling | - |
upper-threshold | Number | 50 | How far from the top/left (in px) does it take to trigger the scrolltoupper event | - |
lower-threshold | Number | 50 | The distance from the bottom/right side (in px) when the scrolltolower event is triggered | - |
scroll-top | Number | - | Set the vertical scroll bar position | - |
scroll-left | Number | - | Set the horizontal scroll bar position | - |
scroll-into-view | String | - | The value should be a child element ID, then scroll to that element and align the top of the element to the top of the scroll area | - |
scroll-with-animation | Boolean | false | Use animated transitions when setting the scroll bar position | - |
scroll-animation-duration | Number | - | When | |
enable-back-to-top | Boolean | false | When you click the top status bar of iOS or double-click the title bar of Android, the scroll bar returns to the top, only supporting vertical direction | |
trap-scroll | Boolean | false | When scrolling vertically, when scrolling to the top or bottom, the page scrolling is forcibly prohibited, and only the scroll-view itself is scrolled | |
onScrollToUpper | EventHandle | - | Scrolling to the top/left will trigger the scrolltoupper event | - |
onScrollToLower | EventHandle | - | Scrolling to the bottom/right will trigger the scrolltolower event | - |
onScroll | EventHandle | - | Trigger when scrolling, | - |
onTouchStart | EventHandle | - | Touch action to start | |
onTouchMove | EventHandle | - | Move after touch | |
onTouchEnd | EventHandle | - | Touch action ends | |
onTouchCancel | EventHandle | - | Touch actions are interrupted by incoming call reminders and pop-up windows |
When using vertical scrolling, you need to set a fixed height via ACSS.
Code sample
<view class="page">
<view class="page-description">Scroll view area</view>
<view class="page-section">
<view class="page-section-title">vertical scroll</view>
<view class="page-section-demo">
<scroll-view scroll-y="{{true}}" style="height: 200px;" onScrollToUpper="upper" onScrollToLower="lower" onScroll="scroll" scroll-into-view="{{toView}}" scroll-top="{{scrollTop}}">
<view id="blue" class="scroll-view-item bc_blue"></view>
<view id="red" class="scroll-view-item bc_red"></view>
<view id="yellow" class="scroll-view-item bc_yellow"></view>
<view id="green" class="scroll-view-item bc_green"></view>
</scroll-view>
</view>
<view class="page-section-btns">
<view onTap="tap">next</view>
<view onTap="tapMove">move</view>
<view onTap="scrollToTop">scrollToTop</view>
</view>
</view>
<view class="page-section">
<view class="page-section-title">horizontal scroll</view>
<view class="page-section-demo">
<scroll-view class="scroll-view_H" scroll-x="{{true}}" style="width: 100%" >
<view id="blue2" class="scroll-view-item_H bc_blue"></view>
<view id="red2" class="scroll-view-item_H bc_red"></view>
<view id="yellow2" class="scroll-view-item_H bc_yellow"></view>
<view id="green2" class="scroll-view-item_H bc_green"></view>
</scroll-view>
</view>
</view>
</view>const order = ['blue', 'red', 'green', 'yellow'];
Page({
data: {
toView: 'red',
scrollTop: 100,
},
upper(e) {
console.log(e);
},
lower(e) {
console.log(e);
},
scroll(e) {
console.log(e.detail.scrollTop);
},
scrollToTop(e) {
console.log(e);
this.setData({
scrollTop: 0,
});
},
});Tips
scroll-into-viewhas a higher priority thanscroll-top.Since scrolling
scroll-viewprevents page bounce, soonPullDownRefreshwill not be triggered when scrolling withscroll-view.