HomeDocs
Skip to main content

scroll-view

Introduction

A scrollable view area. When using vertical scrolling, scroll-view needs to have a fixed height defined by setting the height CSS property. The length unit for component properties defaults to pixels (px).

Property Description

Property NameTypeDefault ValueRequiredDescriptionMinimum Version
scroll-xBooleanFALSENoAllows horizontal scrolling2.2.0
scroll-yBooleanFALSENoAllows vertical scrolling2.2.0
upper-thresholdNumber50NoDistance from top / left when scrolltoupper event is triggered2.2.0
lower-thresholdNumber50NoDistance from bottom / right when scrolltolower event is triggered2.2.0
scroll-topNumber-NoSets position of vertical scroll bar2.2.0
scroll-leftNumber-NoSets position of horizontal scroll bar2.2.0
scroll-into-viewString-NoScrolls to child element in set direction2.2.0
scroll-with-animationBooleanFALSENoUses animation transition when setting scroll bar position2.2.0
scroll-animation-durationNumber200NoDuration of animation transition when setting scroll bar position2.2.0
refresher-enabledBooleanFALSENoEnables pull-to-refresh functionality2.2.0
refresh-stateBooleanFALSENoSets current pull-to-refresh state2.2.0
refresher-thresholdNumber50NoSets custom pull-to-refresh threshold2.2.0
pulling-refresh-textStringPullingNoSets custom text for pull-to-refresh pulling process2.2.0
loosing-refresh-textStringLoosingNoSets custom text for pull-to-refresh releasing process2.2.0
loading-refresh-textStringLoadingNoSets custom text for pull-to-refresh loading process2.2.0
success-refresh-textStringSuccessNoSets custom text for pull-to-refresh success2.2.0
refresh-durationNumber300NoSets custom pull-to-refresh animation transition duration2.2.0
scrolltoupperEventHandle-NoTriggered when scrolled to top / left2.2.0
scrolltolowerEventHandle-NoTriggered when scrolled to bottom / right2.2.0
onscrollEventHandle-NoTriggered when scrolling2.2.0
refreshEventHandle-NoTriggered when pull-to-refresh2.2.0
strict-modeBooleanTRUENoDetermines whether scrolltoupper and scrolltolower events judge the direction of hand sliding3.3.1
scroll-refresh-enabledBooleanFALSENoEnables pull-up refresh function3.3.1
loadmore-enabledBooleanFALSENoEnables pull-up load more function (recommended to open when there is no more content at the bottom, to avoid conflicts during scrolling)3.5.1
loadmore-stateBooleanFALSENoSets the current pull-up load state (true indicates that pull-up loading has been triggered, false indicates that pull-up loading has not been triggered). It can be used with the loadmore event to control the closing of pull-up loading3.5.1
loadmore-thresholdNumber50NoSets custom pull-up load threshold3.5.1
bottom-pulling-refresh-textStringPullingNoSets custom text for pull-up load pulling process3.5.1
bottom-loosing-refresh-textStringLoosingNoSets custom text for pull-up load releasing process3.5.1
bottom-loading-refresh-textStringLoadingNoSets custom text for pull-up load loading process3.5.1
bottom-success-refresh-textStringSuccessNoSets custom text for pull-up load success3.5.1
loadmore-durationNumber300NoSets custom pull-up load animation transition duration3.5.1
loadmoreEventHandleNoTriggered when pull-up to refresh. After triggering, it needs to be manually closed with loadmore-state3.5.1

Examples

Example 1: Vertical Scroll

<view class="page-section mt16">
<view class="page-section-title">
<text>Vertical Scroll</text>
</view>
<view class="page-section-spacing">
<scroll-view
style="height: 300px"
:scroll-y="true"
:scroll-top="scrollTop"
:scroll-into-view="scrollIntoView"
:scroll-with-animation="true"
:scroll-animation-duration="120"
:refresh-state="freshY"
:refresher-enabled="true"
loosing-refresh-text="Release to trigger pull-down refresh"
bind:refresh="refreshY"
bind:scrolltoupper="scrolltoupperY"
bind:scrolltolower="scrolltolowerY"
bind:onscroll="handleScrollY"
>
<template v-slot:pulling>
<h1>Custom Pulling</h1>
</template>
<view id="demo1" class="scroll-view-item demo-text-1">A</view>
<view id="demo2" class="scroll-view-item demo-text-2">B</view>
<view id="demo3" class="scroll-view-item demo-text-3">C</view>
<view id="demo4" class="scroll-view-item demo-text-1">A</view>
<view id="demo5" class="scroll-view-item demo-text-2">B</view>
<view id="demo6" class="scroll-view-item demo-text-3">C</view>
</scroll-view>
</view>
<view class="mt12">
<button bind:tap="toNextY">to NextY</button>
<button class="ml12" bind:tap="tapMove">tap move</button>
<button class="ml12" bind:tap="scrollToDemo">scroll to demo3</button>
</view>
</view>
Page({
data: {
freshY: false,
scrollTop: 0,
scrollIntoView: '',
},

refreshY() {
this.setData({
freshY: true,
});
setTimeout(() => {
this.setData({
freshY: false,
});
}, 1000);
},
handleScrollY(data) {
console.log('handleScrollY', data);
},
scrolltoupperY() {
dlt.showToast('scrolltoupperY');
},
scrolltolowerY() {
dlt.showToast('scrolltolowerY');
},

toNextY() {
const top = this.data.scrollTop;
const step = Math.floor(top / 150);
const next = (step + 1) * 150;

this.setData({
scrollTop: next > 750 ? 0 : next,
});
},

tapMove() {
this.setData({
scrollTop: this.data.scrollTop + 20 > 750 ? 0 : this.data.scrollTop + 20,
});
},

scrollToDemo() {
this.setData({
scrollIntoView: 'demo3',
});
setTimeout(() => {
this.setData({
scrollIntoView: '',
});
}, 300);
},
});
.scroll-view-item {
height: 300px;
font-size: 18px;
color: #ffffff;
display: flex;
position: relative;
align-items: center;
justify-content: center;
position: relative;
z-index: 1000;
}
.demo-text-1 {
background-color: #1aad19;
}
.demo-text-2 {
background-color: #2782d7;
}
.demo-text-3 {
background-color: #f1f1f1;
color: #353535;
}

Example 2: Horizontal Scroll

<view class="page-section mt16">
<view class="page-section-title">
<text>Horizontal Scroll</text>
</view>
<view class="page-section-spacing">
<scroll-view
class="scroll-view_H"
:scroll-x="true"
bind:refresh="refreshX"
:refresh-state="freshX"
bind:scrolltoupper="scrolltoupperX"
bind:scrolltolower="scrolltolowerX"
>
<view id="demox1" class="scroll-view-item_H demo-text-1">A</view>
<view id="demox2" class="scroll-view-item_H demo-text-2">B</view>
<view id="demox3" class="scroll-view-item_H demo-text-3">C</view>
</scroll-view>
</view>
</view>
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.