我想创建一个类似轮播的元素,单击下一个用户在验证当前输入后导航到下一个问题,单击上一个相同。在最后一个问题中,提交表单并显示输出。
动画必须是缓入/缓出类型。每个问题从右侧缓入,单击下一个问题,当前问题从左侧缓入,同时下一个问题从右侧缓入。问题在数组中。
编辑:
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];
}
}