我想創建一個類似元素的輪播,點擊下一個用戶在驗證當前輸入後點擊下一個問題,點擊之前的點擊。在最後一個問題中,表單被提交併顯示輸出。Angular 2:在* ngFor中動畫數據?
動畫必須是緩入/緩出類型。每個問題從右向右輕鬆點擊,當前問題從左側緩解,同時下一個問題從右側緩解。問題在數組中。
被修改:
HTML:
<div [@questionAnimation]="orientation">
{{selectedQuestion.statement}}<br/>
{{selectedQuestion.helperText}}
<md-input [(ngModel)]="selectedQuestion.answer" type="{{selectedQuestion.type}}"
maxlength="{{selectedQuestion.maxLength}}"
min="{{selectedQuestion.min}}" max="{{selectedQuestion.max}}"
(keydown)="nextOnEnter($event)" required>
<span md-prefix [innerHTML]="selectedQuestion.prefix"></span>
<span md-suffix [innerHTML]="selectedQuestion.suffix"></span>
</md-input>
</div>
<button md-button (click)="prev()">Previous</button>
<button md-button (click)="next()">Next</button>
動畫:
animations: [
trigger('questionAnimation', [
state('next', style({transform: 'translateX(0)', opacity: 1.0})),
state('prev', style({transform: 'translateX(0)', opacity: 1.0})),
transition('next => prev', style({transform: 'translateX(-100%)', opacity: 1.0}), animate('300ms')),
transition('* => next', style({transform: 'translateX(-100%)', opacity: 0.0}), animate('900ms'))
])
]
導航代碼:
next() {
this.orientation = 'next';
let index = this.questions.indexOf(this.selectedQuestion);
if (this.questions[index + 1]) {
this.selectedQuestion = this.questions[index + 1];
} else {
this.calculate();
}
}
prev() {
this.orientation = 'prev';
let index = this.questions.indexOf(this.selectedQuestion);
if (this.questions[index - 1]) {
this.selectedQuestion = this.questions[index - 1];
} else {
this.selectedQuestion = this.questions[0];
}
}
什麼問題?你有什麼嘗試?你在哪裏失敗?請將代碼添加到您的問題中,以展示您嘗試完成的內容以及您嘗試的內容。 –
我已經添加了代碼,但我真的懷疑這是否正確。 –