1、竖向滚动

首先从简单的来,竖向滚动很简单,只用记住两点即可:

  • 首先得设置scroll-y属性;
  • 其次,一定要给scroll-view设置一个height高度;
    <scroll-view scroll-y style="height: 200px;">
      <view class="green" style="width: 100%; height: 200px; background: green;"></view>
      <view class="red" style="width: 100%; height: 200px; background: red;"></view>
      <view class="yellow" style="width: 100%; height: 200px; background: yellow;"></view>
      <view class="blue" style="width: 100%; height: 200px; background: blue;"></view>
    </scroll-view>

    2、横向滚动

    横向滚动就有点坑了...

    • 首先还是要设置滚动方向为scroll-x

    • 然后要给<scroll-view></scroll-view>设置white-spacenowrap不换行;

    • 最后需要将容器中包裹的标签的display属性设置为inline-block

    • <scroll-view scroll-x style="width: 100%; white-space: nowrap;">
        <view class="green" style="display: inline-block; width: 200px; height: 200px; background: green;"></view>
        <view class="red" style="display: inline-block; width: 200px; height: 200px; background: red;"></view>
        <view class="yellow" style="display: inline-block; width: 200px; height: 200px; background: yellow;"></view>
        <view class="blue" style="display: inline-block; width: 200px; height: 200px; background: blue;"></view>
      </scroll-view>

       

    具体参数看官网   https://developers.weixin.qq.com/miniprogram/dev/component/scroll-view.html

posted on 2020-08-04 18:29  京鸿一瞥  阅读(473)  评论(0)    收藏  举报