在微信小程序中scroll-view是一个非常常用的组件,但是在使用的过程中有可能达到的效果与我们想要的不一致,接下来我将总结我在使用scroll-view中遇到的问题和一些技巧:
(1)横向滑动(scroll-x="true")
1)如果我们想要在scroll-view中使用flex布局,我们需要在scroll-view设置属性enable-flex="true",并且在srcoll-view的style中设置 white-space: nowrap,另外需要在scroll-view的子项中设置display:inline-block。如下所示
<!--wxml-->
<view class="category">
<scroll-view class="category_banner" scroll-x enable-flex>
<view class="category_banner_item"
wx:for="{
{brotherCategory}}"
wx:key="id"
>{
{item.name}}</view>
</scroll-view>
</view>
/*wxss*/
.category_banner{
width:750rpx;
white-space: nowrap;
}
.category_banner_item{
display: inline-block;