Skip to content

Commit 6189879

Browse files
committed
Animation Entering and leaving
1 parent eac5d05 commit 6189879

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

src/pages/home/home.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@
3131
<button ion-button (click)="flickerIcon()">Test</button>
3232
<ion-badge item-end><img src="assets/img/eye.png" [@flicker]='flicker'></ion-badge>
3333
</ion-item>
34+
<ion-item-divider color="light">Animation Entering and leaving heroes</ion-item-divider>
35+
<ion-item>
36+
<button ion-button (click)="addHeroe()">Add heroe</button>
37+
<button ion-button (click)="removeHeroe()">Remove heroe</button>
38+
<ul>
39+
<li *ngFor="let hero of heroes" [@flyInOut]="'in'">{{hero}}</li>
40+
</ul>
41+
</ion-item>
42+
<ion-item-divider color="light">Animation Automatic property calculation</ion-item-divider>
43+
<ion-item>
44+
<button ion-button (click)="addHeroe1()">Add heroe</button>
45+
<button ion-button (click)="removeHeroe1()">Remove heroe</button>
46+
<ul>
47+
<li *ngFor="let hero of heroes1" [@shrinkOut]="'in'"> {{hero}}</li>
48+
</ul>
49+
</ion-item>
3450
</ion-list>
3551

3652
</ion-content>

src/pages/home/home.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
11
page-home {
22

3+
ul {
4+
list-style-type: none;
5+
padding: 0;
6+
}
7+
8+
li {
9+
display: block;
10+
width: 120px;
11+
line-height: 50px;
12+
padding: 0 10px;
13+
box-sizing: border-box;
14+
background-color: #eee;
15+
border-radius: 4px;
16+
margin: 10px;
17+
cursor: pointer;
18+
overflow: hidden;
19+
white-space: nowrap;
20+
}
21+
322
}

src/pages/home/home.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ import { NavController } from 'ionic-angular';
6666
style({opacity: 0, offset: 0.5}),
6767
style({opacity: 1, offset: 1.0}),
6868
])))
69+
]),
70+
trigger('flyInOut', [
71+
state('in', style({transform: 'translateX(0)'})),
72+
transition('void => *', [
73+
style({transform: 'translateX(-100%)'}),
74+
animate(300)
75+
]),
76+
transition('* => void', [
77+
animate(300, style({transform: 'translateX(100%)'}))
78+
])
79+
]),
80+
trigger('shrinkOut', [
81+
state('in', style({height: '*'})),
82+
transition('* => void', [
83+
style({height: '*'}),
84+
animate(250, style({height: 0}))
85+
])
6986
])
7087
],
7188
})
@@ -81,7 +98,27 @@ export class HomePage {
8198

8299
private resize: string = 'small';
83100

101+
private heroes: any;
102+
private heroes1: any;
103+
private currentIndex: number = 0;
104+
105+
static ALL_HEROES = [
106+
'Windstorm',
107+
'RubberMan',
108+
'Bombasto',
109+
'Magneta',
110+
'Dynama',
111+
'Narco',
112+
'Celeritas',
113+
'Dr IQ',
114+
'Magma',
115+
'Tornado',
116+
'Mr. Nice'
117+
];
118+
84119
constructor(public navCtrl: NavController) {
120+
this.heroes = [];
121+
this.heroes1 = [];
85122

86123
}
87124

@@ -108,4 +145,32 @@ export class HomePage {
108145
this.flicker = (this.flicker === 'start' ? 'end' : 'start');
109146
}
110147

148+
addHeroe() {
149+
if (this.currentIndex <= HomePage.ALL_HEROES.length - 1) {
150+
this.heroes.push(HomePage.ALL_HEROES[this.currentIndex]);
151+
this.currentIndex += 1;
152+
}
153+
else this.currentIndex = 0;
154+
}
155+
156+
removeHeroe() {
157+
if (this.heroes.length > 0) {
158+
this.heroes.splice(this.heroes.length - 1, 1);
159+
}
160+
}
161+
162+
addHeroe1() {
163+
if (this.currentIndex <= HomePage.ALL_HEROES.length - 1) {
164+
this.heroes1.push(HomePage.ALL_HEROES[this.currentIndex]);
165+
this.currentIndex += 1;
166+
}
167+
else this.currentIndex = 0;
168+
}
169+
170+
removeHeroe1() {
171+
if (this.heroes1.length > 0) {
172+
this.heroes1.splice(this.heroes1.length - 1, 1);
173+
}
174+
}
175+
111176
}

0 commit comments

Comments
 (0)