HarmonyOS 想实现从左侧滑出一张运营广告位的动画,10秒后消失?

想实现从左侧滑出一张运营广告位的动画,10秒后消失,效果如下图

阅读 559
1 个回答

参考下demo

// xxx.ets
@Entry
@Component
struct Index {
  @State xOffset: number = -100

  onPageShow(): void {
    setTimeout(()=>{
      animateTo({
        duration: 2000,
        curve: Curve.EaseOut,
        playMode: PlayMode.Normal,
        onFinish: () => {
          console.info('play end')
        }
      }, () => {
        this.xOffset = 0
      })
    },1000)
    setTimeout(()=>{
      animateTo({
        duration: 2000,
        curve: Curve.EaseOut,
        playMode: PlayMode.Normal,
        onFinish: () => {
          console.info('play end')
        }
      }, () => {
        this.xOffset = -100
      })
    },10000)
  }

  build() {
    Column({ space: 20 }) {
      Flex({ direction: FlexDirection.Row }) {
        Image($r('app.media.ic_banner01'))
          .width(100)
          .height(70)
          .offset({ x:this.xOffset })
      }
    }
    .backgroundColor(Color.Yellow)
    .width('100%')
    .height('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进