我的 ionicionic3从入门到精通(内含BUG修复)

ionic3 添加动画

2017-07-03  本文已影响153人  OnceWhite

第一种方法

npm install web-animations-js
//在main.ts 导入
import 'web-animations-js/web-animations.min';
//在app.module.ts
 import { BrowserAnimationsModule } from '@angular/platform-browser/animations'

  imports: [
    BrowserModule,
    BrowserAnimationsModule,   
    IonicModule.forRoot(MyApp)
  ]
// in HTML 
<button ion-button (click)="fadeIt()" >fade it!</button>
<p [@fading] = 'visableState'>hhhahahahahhaha</p>
// in .ts
import { trigger ,state,transition,animate,style} from "@angular/animations";
@Component({
  selector: 'page-home',
  templateUrl: 'home.html',

  animations:[
      trigger('fading',[
         state('visable',style({
            opacity: 1
         })),
         state('invisable', style({
           opacity: 0
         })),
         transition('* => *',animate('.5s'))
      ])
  ]
})
// in export class  xxPage
 visableState = 'visable';
fadeIt(){
      this.visableState = (this.visableState == 'visable')?'invisable':'visable';
   }

第二种方法

npm install css-animator
// in index.html
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css">
import { AnimatesDirective, AnimationService } from 'css-animator'

 declarations: [
    MyApp,
    AnimatesDirective
  ],
providers: [
    StatusBar,
    SplashScreen,
    AnimationService,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
// in HTML  点击即可看到动画
<div animates #animation="animates" text-center>
     <button ion-button (click)="animation.start({type:'shake',duration:'1000'})" >click it!</button>
 </div>
上一篇下一篇

猜你喜欢

热点阅读