Animating transition from one component to another in Ionic 2

ⅰ亾dé卋堺 提交于 2019-12-22 11:18:11

问题


I have having two components in my app.

I need to animate the transition between these those pages.

I need to flip the page 1 and then page 2 should appear.

I there any plugin to do it in ionic 2.

Any reference/example will be appreciated.

I am using this.navController.setRootPage(Page2) to go from one page to another.


回答1:


I don't know the Ionic framework, but here's a demo (plunker) how it works with plain Angular2: http://plnkr.co/edit/yJHjL5ap9l4MwOimCyyY?p=preview

Using the animations feature of the Component decorator:

Component A

@Component({
  selector: 'home',
  directives: [ROUTER_DIRECTIVES],
  template: `
  <div class="radibre">
  Home page
  </div>
  `,
  styles: ['.radibre { width: 200px; height: 100px; background: red; color: white; }'],
   host: {
     '[@routeAnimation]': 'true',
     '[style.display]': "'block'",
     '[style.position]': "'absolute'"
   },
  animations: [
    trigger('routeAnimation', [
      state('*', style({transform: 'translateX(0)', opacity: 1})),
      transition('void => *', [
        style({transform: 'translateX(-100%)', opacity: 0}),
        animate(1000)
      ]),
      transition('* => void', animate(1000, style({transform: 'translateX(100%)', opacity: 0})))
    ])
  ]
})

export class Home {
  constructor() { }
}

Component B

@Component({
  selector: 'page',
  template: `
  <div class="page">Another page</div>`,
  styles: ['.page { width: 200px; height: 100px; background: green; color: white; }'],
   host: {
     '[@routeAnimation]': 'true',
     '[style.display]': "'block'",
     '[style.position]': "'absolute'"
   },
  animations: [
    trigger('routeAnimation', [
      state('*', style({transform: 'translateX(0)', opacity: 1})),
      transition('void => *', [
        style({transform: 'translateX(-100%)', opacity: 0}),
        animate(1000)
      ]),
      transition('* => void', animate(1000, style({transform: 'translateX(100%)', opacity: 0})))
    ])
  ]
})

export class Page {
  constructor() { }
}


来源:https://stackoverflow.com/questions/39000962/animating-transition-from-one-component-to-another-in-ionic-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!