ionic4 페이지 오른쪽 슬라이딩 애니메이션 효과 구현

2805 단어
파일에 코드 직접 부착
import { MyApp } from "./app.component";
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { RouteReuseStrategy } from '@angular/router';
import { AppRoutingModule } from './app-routing.module';
import { IonicGestureConfig } from './IonicGestureConfig';
import { CommonModule } from '@angular/common';
import { Animation } from '@ionic/core';
@NgModule({
  declarations: [
    MyApp
  ],
  imports: [
    BrowserModule,
    CommonModule,
    IonicModule.forRoot({
      backButtonText: '',
      mode: "md",
      navAnimation: (AnimationC: Animation, baseEl: any, position?: any): Promise => {
        const baseAnimation = new AnimationC();
        const hostEl = (baseEl.host || baseEl) as HTMLElement;

        const wrapperAnimation = new AnimationC();
        const wrapperAnimation2 = new AnimationC();
        if (position.direction == "forward") {
          wrapperAnimation.addElement(position.enteringEl);
          wrapperAnimation.fromTo('transform', `translateX(100%)`, 'translateX(0px)');
          wrapperAnimation.fromTo('opacity', 0.3, 1);

          wrapperAnimation2.addElement(position.leavingEl);
          wrapperAnimation2.fromTo('transform', `translateX(0)`, 'translateX(-50%)');
          wrapperAnimation2.fromTo('opacity', 1, 0.5);
        }

        if (position.direction == "back") {
          wrapperAnimation.addElement(position.leavingEl);
          wrapperAnimation.fromTo('transform', `translateX(0)`, 'translateX(100%)');
          wrapperAnimation.fromTo('opacity', 1, 0);

          wrapperAnimation2.addElement(position.enteringEl);
          wrapperAnimation2.fromTo('transform', `translateX(-90%)`, 'translateX(0)');
          wrapperAnimation2.fromTo('opacity', 0.5, 1);
        }
        return Promise.resolve(baseAnimation
          .addElement(hostEl)
          .easing('cubic-bezier(.36,.66,.04,1)')
          .duration(600)
          .add(wrapperAnimation)
          .add(wrapperAnimation2));
      }
    }),
    AppRoutingModule
  ],
  bootstrap: [MyApp],
  entryComponents: [],
  providers: [
    StatusBar,
    SplashScreen,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  ]
})
export class AppModule { }


키 코드app.module.ts 그 부분을 붙이면 사용할 수 있어요.
(오리지널 문장, 전재 출처를 밝혀 주십시오, 감사합니다)

좋은 웹페이지 즐겨찾기