中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
微信扫码分享
@Component export struct Test { @State message: string = 'Hello World'; @State opacityValue: number = 1 build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold) .opacity(this.opacityValue) Button("开始动画").onClick(() => { animateTo({ duration: 1000, iterations: -1, playMode: PlayMode.AlternateReverse }, () => { this.opacityValue = 0 }) }) Button("结束动画").onClick(() => { animateTo({ duration: 0, iterations: 1, onFinish: () => { this.opacityValue = 1 } }, () => { this.opacityValue = 0.9 }) }) } .width('100%') } .height('100%') } }