效果图(上下滚动、左右滚动)
代码示例
xxx.wxml结构代码
<view class="sectionVertical">
<view class="sectionTitle">vertical scroll</view>
<scroll-view scroll-y="true" class='scrollVertical'>
<view class="row bc_green"></view>
<view class="row bc_red"></view>
<view class="row bc_yellow"></view>
<view class="row bc_blue"></view>
<view class="row bc_red"></view>
<view class="row bc_green"></view>
<view class="row bc_blue"></view>
</scroll-view>
</view>
<view class="sectionHorizontal">
<view class="sectionTitle">horizontal scroll</view>
<scroll-view scroll-x='true'>
<view class='scrollHorizontal'>
<view class="row bc_green"></view>
<view class="row bc_red"></view>
<view class="row bc_yellow"></view>
<view class="row bc_blue"></view>
<view class="row bc_green"></view>
<view class="row bc_red"></view>
<view class="row bc_yellow"></view>
<view class="row bc_blue"></view>
</view>
</scroll-view>
</view>
xxx.wxss样式代码
/* pages/modules/containerPages/scrollviewPage/scrollview.wxss */
.sectionVertical{
background-color: purple;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
/* 按比例布局 */
/* position: absolute;
width: 100%;
height: 50%; */
/* 按大小布局 */
height: 230px;
}
.sectionTitle{
background-color: orange;
text-align: center;
color: red;
line-height: 30px;
font-size: 20px;
/* 按比例布局 */
/* width: 100%;
height: 20%; */
/* 按大小布局 */
width: 100%;
height: 30px;
}
.scrollVertical{
flex: 1;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
/* 按比例布局 */
/* height: 80%; */
/* 按大小布局 */
height: 200px;
}
.scrollVertical .row{
flex: 1;
/* 按大小布局 */
height: 50px;
}
.sectionHorizontal{
background-color: Moccasin;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
/* margin-top: 200px; */
/* margin-bottom: 0px; */
width: 100%;
height: 130px;
}
.scrollHorizontal{
display: flex;
justify-content: flex-start;
flex-direction: row;
flex-wrap: nowrap;
width: 100%;
height: 100px;
}
.scrollHorizontal .row{
flex-shrink: 0;
width: 100px;
height: 100px;
}
.bc_green{
background-color: MediumAquamarine;
}
.bc_red{
background-color: LightPink;
}
.bc_yellow{
background-color: LightGoldenrodYellow;
}
.bc_blue{
background-color: MediumPurple;
}