完整示例参考如下:
@Entry @Component struct CurtainCoverageDemo { @State y: number = 400; build() { Column() { // 模拟幕布 Column() { Text('幕布组件') .textAlign(TextAlign.Center) .align(Alignment.Center); } .justifyContent(FlexAlign.Center) .size({ width: '100%', height: 100 }) .position({ top: 250 }) .zIndex(100) .backgroundColor('#f0f2f4'); // 被遮罩的运动组件 Row() { Text() .size({ width: 60, height: 60 }) .fontSize(12) .fontColor('#81D3F8') .borderRadius(40) .backgroundColor('#1d52c2') .zIndex(50); } .size({ width: 60, height: 60 }) .margin({ top: 50 }) .translate({ y: this.y }) // 向上平移 .onClick(() => { setTimeout(() => { this.getUIContext().animateTo({ duration: 1000 }, () => { this.y = 230; }); }, 1000); }); } .width('100%') .height('100%') .backgroundColor(Color.White); } }