小程序组件 scroll-view 中分别有上下竖向滑动和左右横向滑动,在这次项目中刚好需要用到横向滑动,但在测试过程中发现横向滑动没有了效果(静止在那里没移动过,并且换行了),经调试发现:
1.scroll-view 中的需要滑动的元素不可以用 float 浮动;
2.scroll-view 中的包裹需要滑动的元素的大盒子用 display:flex; 是没有作用的;
3.scroll-view 中的需要滑动的元素要用 display:inline-block; 进行元素的横向编排;
4.包裹 scroll-view 的大盒子有明确的宽和加上样式—> overflow:hidden;white-space:nowrap;
废话不多说直接上干货
wxml:
<view class="scroll_box"> <scroll-view class="scroll-view_x" scroll-x style="width: auto;overflow:hidden;"><view class="item_list" wx:for="{
{list}}"><image src="../../images/head.jpg" class="item_book_img" mode="aspectFill"></image><view class="item_book_text">测试数据</view></view></scroll-view></view>
css:
.scroll_box{width: 100%;height: 307rpx;overflow: hidden;padding: 20rpx;background: #fff;white-space: nowrap;}.item_list{width: 160rpx;height: auto;margin-right: 23rpx;display: inline-block;
}