小程序組件 scroll-view 中分別有上下豎向滑動和左右橫向滑動之分,在這次項目中剛好需要用到橫向滑動,但在測試過程中發現橫向滑動沒有了效果(靜止在那里沒移動過),經調試發現:
1.scroll-view 中的需要滑動的元素不可以用 float 浮動;
2.scroll-view 中的包裹需要滑動的元素的大盒子用 display:flex; 是沒有作用的;
3.scroll-view 中的需要滑動的元素要用 dislay:inline-block; 進行元素的橫向編排;
4.包裹 scroll-view 的大盒子有明確的寬和加上樣式--> overflow:hidden;white-space:nowrap;
具體的測試代碼如下
<scroll-view scroll-x class='hot-list graybg'> <view class='hot-good' wx:for="{{hotlist}}"> <image class='backwhite' src='{{item.pic}}'></image> <view class='overhiddent graybg' style='padding:18rpx 0 6rpx 0;'>{{item.name}}</view> <view class='red graybg'>{{item.showPrice}}/天</view> </view> </scroll-view> .hot-list{ padding: 20rpx 0rpx; width: auto; overflow: hidden; white-space: nowrap; } .hot-good{ width: 260rpx; display: inline-block; margin: 0 20rpx; font-size: 24rpx; }
