组件初始在幕布下方,如何实现点击后该组件缓慢运动直至被幕布组件完全遮挡的效果?

完整示例参考如下:
@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); } }
zIndex可设置组件的堆叠顺序,zIndex值大的组件会覆盖在zIndex值小的组件上方。
合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
解决方案
精准高效的一站式服务支持,助力开发者商业成功