微信小程序 scroll-view 左右橫向滑動沒有效果(無法滑動)問題


小程序組件 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;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM