电子说
RollingText.ets 组件封装
/**
* 滚动文字特效
*/
@Component
export default struct RollingText {
private num:number
private timerId: number = -1
@State counter: number = 0
aboutToAppear() {
this.timerId = setInterval(() = > {
this.counter += 1
if(this.counter==this.num){
clearTimeout(this.timerId)
}
}, 1)//2000
}
aboutToDisappear() {
clearTimeout(this.timerId)
}
build(){
Row(){
Text(""+this.counter).fontWeight(700).fontColor('#ffffff').fontSize(14)
}
}
}
import RollingText from '../components/RollingText'
Column(){
Text("控股公司(家)").fontWeight(700).fontColor('#ffffff').fontSize(16)
RollingText({num:1100})
}.margin({left:10})
审核编辑 黄宇
全部0条评论
快来发表一下你的评论吧 !