当时间改变时,例如。second/min/hours/day,我想将动画放在特定的 div 块中。也许我无法弄清楚如何继续前进。
演示:https ://plnkr.co/edit/jvffeaWFCF6eazdIt3OT?p=preview
当第二个变化时,数字应该来自顶部和底部的动画是需要的。
app.component.ts
import {Component,OnInit} from '@angular/core'
import {TitleComponent} './title.component';
import {
Component,
Input,
trigger,
state,
style,
animate,
transition,
group
} from '@angular/core';
@Component({
selector: 'my-app',
template:`
<div class="col-xs-3 time">{{days}}
</div>
<div class="col-xs-3 time">{{hours}}
</div>
<div class="col-xs-3 time">{{minutes}}
</div>
<div [@time] class="col-xs-3 time">{{seconds}}
</div>
`,
animations: [
trigger('time', [
transition(':enter', animate('100ms ease-in')),
transition(':leave', animate('100ms ease-out')),
])
]
styles:[`
.time{
height:100px;
background:black;
color:white;
line-height:100px;
border:1px solid;
text-align:center;
}
`],
})
export class App implements OnInit {
constructor(){
setInterval(()=>{
this.count()
},1000)
}
count(){
var date1 = new Date('2016-12-31 24:00');
var date2 = new Date();
var diffInSeconds = Math.abs(date1 - date2) / 1000;
this.days = Math.floor(diffInSeconds / 60 / 60 / 24);
this.hours = Math.floor(diffInSeconds / 60 / 60 % 24);
this.minutes = Math.floor(diffInSeconds / 60 % 60);
this.seconds = Math.floor(diffInSeconds % 60);
this.milliseconds = Math.round((diffInSeconds - Math.floor(diffInSeconds)) * 1000);
this.hours=('0' + this.hours).slice(-2)
this.minutes=('0' + this.minutes).slice(-2);
this.seconds=('0' + this.seconds).slice(-2);
}
}