Skip to content

DigitRoller 数字翻滚

介绍

数字翻滚动效,支持其他自定义文本滚动。

基础用法

通过 value 属性来设置数字值。

html
<vd-digit-roller :value="123456" />

自定义字符

通过 chars 属性来设置自定义字符。

html
<vd-digit-roller value="1a2b3d4c5e" :chars="chars" />
ts
const chars = '0123456789abcdefghijklmnopqrstuvwxyz';

最小字符长度

通过 minlength 属性来设置自定义字符长度,不足的字符数会自动向前补充。

html
<vd-digit-roller :value="123456" minlength="10" />

自定义样式(卡片)

展示自定义卡片样式示例。

html
<vd-digit-roller
  :value="123456"
  height="48"
  minlength="8"
  custom-class="custom-roller"
>
  <template #text="{ text }">
    <view class="txt">{{ text }}</view>
  </template>
</vd-digit-roller>
scss
.custom-roller {
  color: $vd-white;
  font-size: $vd-font-size-xl;
  font-weight: bold;

  .vd-digit-roller__item {
    margin-right: $vd-gap-xs;
  }

  .vd-digit-roller__text {
    padding: $vd-gap-xs 0;

    > view {
      height: 100%;
    }
  }

  .txt {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 100%;
    border-radius: $vd-radius-md;
    background: $vd-primary;
  }
}

自定义样式(文字)

展示自定义卡片样式示例。

html
<vd-digit-roller
  :value="123456"
  height="40"
  minlength="8"
  custom-class="custom-roller"
>
  <template #text>
    <text></text>
  </template>
</vd-digit-roller>
scss
.custom-roller {
  color: $vd-white;
  font-size: $vd-font-size-xl;
  font-weight: bold;

  .vd-digit-roller__item {
    width: 30px;
    margin-right: $vd-gap-xs;
    border-radius: $vd-radius-md;
    background: $vd-primary;
  }
}

API

Props

参数说明类型默认值
value数值string | number-
chars滚动字符string-
minlength最小字符长度string | number-
duration动画时长,单位 msstring | number1500
autoplay是否自动开始动画booleantrue
height滚动高度string | number120

代替原始 Props

参数说明类型默认值
custom-id根节点idstring-
custom-class根节点类名ClassValue-
custom-style根节点样式StyleValue-

Events

事件名说明回调参数
click点击时触发MouseEvent

Slots

名称说明
text数字文本内容

Expose

方法名说明参数返回值
start开始滚动--
reset重置滚动--

赣ICP备2025061025号-1