首页 > 解决方案 > 动画不是离子中的构造函数

问题描述

我想调整 toastAlert 的动画,但它显示错误我在@ionic/core 中使用动画,我的离子版本是 ionic v5 可能是版本问题,但我不知道如何解决,确实任何人都可以帮助我吗?

ERROR Error: Uncaught (in promise): TypeError: AnimationC is not a constructor
TypeError: AnimationC is not a constructor

这里是customAlertEnter.ts

import { Animation } from '@ionic/core'

export function customAlertEnter(AnimationC: Animation, baseEl: HTMLElement): Promise<Animation> {

    const baseAnimation = new AnimationC();

    const backdropAnimation = new AnimationC();
    backdropAnimation.addElement(baseEl.querySelector('ion-backdrop'));

    const wrapperAnimation = new AnimationC();
    const wrapperElem = baseEl.querySelector('.alert-wrapper') as HTMLElement;
    wrapperAnimation.addElement(wrapperElem);

    wrapperElem.style.top = '0';

    backdropAnimation.fromTo('opacity', 0.01, 0.3);

    wrapperAnimation.beforeStyles({ 'opacity': 1 });
    wrapperAnimation.fromTo('transform', `translateY(-${baseEl.clientHeight}px)`, 'translateY(0px)')

    return Promise.resolve(baseAnimation
      .addElement(baseEl)
      .easing('cubic-bezier(.36, .66, .3, .1, 1)')
      .duration(500)
      .add(wrapperAnimation)
      .add(backdropAnimation));
  }

这是代码showAlert()

  async showAlert(message: string){
    const alert = await this.toastController.create({
      message: message,
      duration: 2000,
      position: 'top',
      enterAnimation: customAlertEnter
    })

谢谢!

标签: javascriptionic-framework

解决方案


推荐阅读