Skip to content

RollingText 翻滚文本

介绍

文本翻滚动效,可以翻滚数字。

TIP

阅读该组件文档前请确保已认真阅读快速上手章节的每一个字

引入

ts
import { IBestRollingText } from "@ibestservices/ibest-ui";

代码演示

基础用法

基础用法

点我查看代码
ts
@Entry
@Component
struct DemoPage {
  build() {
    Column() {
      IBestRollingText({
        targetNum: 123
      })
    }
  }
}

翻滚方向

翻滚方向

点我查看代码
ts
@Entry
@Component
struct DemoPage {
  build() {
    Column() {
      IBestRollingText({
        targetNum: 888,
        rollingDirection: "up"
      })
    }
  }
}

停止顺序

停止顺序

点我查看代码
ts
@Entry
@Component
struct DemoPage {
  build() {
    Column() {
      IBestRollingText({
        targetNum: 54321,
        stopOrder: "rtl"
      })
    }
  }
}

自定义样式

自定义样式

点我查看代码
ts
@Entry
@Component
struct DemoPage {
  build() {
    Column() {
      IBestRollingText({
        startNum: 12345,
        targetNum: 54321,
        numWidth: 40,
        numHeight: 54,
        textBgColor: '#1989fa',
        fontColor: '#fff',
        fontSize: 24,
        gap: 6,
        radius: 4
      })
    }
  }
}

手动控制

手动控制

点我查看代码
ts
import { IBestRollingTextController, IBestButton } from "@ibestservices/ibest-ui";
@Entry
@Component
struct DemoPage {
  controller: IBestRollingTextController = new IBestRollingTextController()
  build() {
    Column() {
      IBestRollingText({
        targetNum: 54321,
        autoStart: false,
        numWidth: 40,
        numHeight: 54,
        textBgColor: '#1989fa',
        fontColor: '#fff',
        fontSize: 24,
        gap: 6,
        radius: 4,
        controller: this.controller
      })
      Row({space: SPACE.MD}){
        IBestButton({
          type: 'primary',
          text: "开始",
          onBtnClick: () => {
            this.controller.start()
          }
        })
        IBestButton({
          type: 'primary',
          text: "重置",
          onBtnClick: () => {
            this.controller.reset()
          }
        })
      }.margin({top: SPACE.SM})
    }
  }
}

API

IBestAvatar @Props

参数说明类型默认值
startNum起始数值number0
targetNum目标数值number0
duration动画时长,单位msnumber2000
rollingDirection翻滚方向,可选值up downstringdown
autoStart是否自动开始翻滚booleantrue
delay自动翻滚延迟时长,单位msnumber500
stopOrder停止顺序,可选值ltr rtlstringltr
numWidth单个数位宽度string | number15
numHeight单个数位高度string | number40
gap数字间距string | number0
textBgColor数字背景颜色ResourceColor''
fontColor文字颜色ResourceColor#323233
fontSize文字大小string | number14
radius单个数位边框圆角string | number0
controller控制器IBestRollingTextController-

IBestRollingTextController API

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

主题定制

组件提供了下列颜色变量,可用于自定义深色/浅色模式样式,使用方法请参考 颜色模式 章节,如需要其它颜色变量可提 issue

名称描述默认值
ibest_rolling_text_text_color文字颜色#323233