Skip to content

ScrollX 横向滚动列表 1.0.11

手机扫码预览
15:57

组件名:rice-scroll-x

左右滑动的列表。1.0.11 版本开始支持
右侧模拟器无法滑动,请使用真机进行预览。

平台兼容性

uni-app x

AndroidiOS鸿蒙Next微信小程序h5

基础用法

html
<rice-scroll-x>
  <view v-for="item in list" :key="item.text" class="scroll-item">
    <image :src="item.image" class="image" />
    <text class="text">{{item.text}}</text>
  </view>
</rice-scroll-x>
ts
  type List = {
    text : string,
    image : string,
  }
  const list = ref<List[]>([{
    text: "充值中心",
    image: "/static/images/czzx.png"
  }, {
    text: "金币家园",
    image: "/static/images/jb.png"
  }, {
    text: "热门推荐",
    image: "/static/images/hot.png"
  }, {
    text: "超市购物",
    image: "/static/images/shop.png"
  }, {
    text: "优惠活动",
    image: "/static/images/yhq.png"
  }, {
    text: "外卖配送",
    image: "/static/images/wm.png"
  }, {
    text: "充值中心",
    image: "/static/images/czzx.png"
  }, {
    text: "金币家园",
    image: "/static/images/jb.png"
  }, {
    text: "优惠活动",
    image: "/static/images/yhq.png"
  }, {
    text: "外卖配送",
    image: "/static/images/wm.png"
  }, {
    text: "超市购物",
    image: "/static/images/shop.png"
  }])
css
.scroll-item {
  align-items: center;
  height: 60px;
  width: 76px;
}

.image {
  height: 32px;
  width: 32px;
}

.text {
  color: var(--demo-text-color-2);
  font-size: 12px;
  margin-top: 6px;
}

自定义样式

  • indicator-color 设置指示器的背景颜色
  • indicator-active-color 设置滑块的背景颜色
  • indicator-width 设置指示器的宽度
  • indicator-bar-width 设置滑块的宽度
  • indicator-height 设置指示器的高度
html
<rice-scroll-x  indicator-color="rgba(213, 93, 93,.2)" indicator-active-color="#e66464" indicator-width="60px"
  indicator-bar-width="25px">
  <view v-for="item in list" :key="item.text" class="scroll-item">
    <image :src="item.image" class="image" />
    <text class="text">{{item.text}}</text>
  </view>
</rice-scroll-x>

多行菜单

html
<rice-scroll-x>
  <view class="scroll-more">
    <view v-for="(menu,index) in list2" :key="index" class="scroll-more__menu">
      <view v-for="item in menu" :key="index" class="scroll-item">
        <image :src="item.image" class="image" />
        <text class="text">{{item.text}}</text>
      </view>
    </view>
  </view>
</rice-scroll-x>
ts
type List = {
  text : string,
  image : string,
}
const list2 = ref<List[][]>([
  [{
    text: "充值中心",
    image: "/static/images/czzx.png"
  }, {
    text: "外卖配送",
    image: "/static/images/wm.png"
  }, {
    text: "金币家园",
    image: "/static/images/jb.png"
  }, {
    text: "热门推荐",
    image: "/static/images/hot.png"
  }, {
    text: "优惠活动",
    image: "/static/images/yhq.png"
  }, {
    text: "金币家园",
    image: "/static/images/jb.png"
  }, {
    text: "超市购物",
    image: "/static/images/shop.png"
  }, {
    text: "充值中心",
    image: "/static/images/czzx.png"
  }, {
    text: "优惠活动",
    image: "/static/images/yhq.png"
  }, {
    text: "外卖配送",
    image: "/static/images/wm.png"
  }],
  [{
    text: "热门推荐",
    image: "/static/images/hot.png"
  }, {
    text: "超市购物",
    image: "/static/images/shop.png"
  }, {
    text: "优惠活动",
    image: "/static/images/yhq.png"
  }, {
    text: "外卖配送",
    image: "/static/images/wm.png"
  }, {
    text: "充值中心",
    image: "/static/images/czzx.png"
  }, {
    text: "金币家园",
    image: "/static/images/jb.png"
  }, {
    text: "优惠活动",
    image: "/static/images/yhq.png"
  }, {
    text: "外卖配送",
    image: "/static/images/wm.png"
  }, {
    text: "充值中心",
    image: "/static/images/czzx.png"
  }, {
    text: "金币家园",
    image: "/static/images/jb.png"
  }]
])
css
.scroll-item {
  align-items: center;
  height: 60px;
  width: 76px;
}

.scroll-more {
  &__menu {
    margin-top: 16px;
    flex-direction: row;
  }
}

.image {
  height: 32px;
  width: 32px;
}

.text {
  color: var(--demo-text-color-2);
  font-size: 12px;
  margin-top: 6px;
}

API

Props

属性名类型说明默认值
show-indicatorBoolean是否显示指示器true
indicator-widthString|Number指示器的宽度50px
indicator-heightString|Number指示器的高度4px
indicator-bar-widthString|Number滑块的宽度20px
indicator-colorString指示器的背景颜色-
indicator-active-colorString滑块的背景颜色-
indicator-styleObject自定义指示器的style-
custom-styleObject自定义style-

Events

事件名说明回调参数
scrollToLeft滚到到最左边时触发的事件-
scrollToRight滚到到最右边时触发的事件-

类型定义

组件导出如下类型

ts
// 组件类型
const scrollXRef=ref<RiceScrollXComponentPublicInstance|null>(null)