你可以用像这样的角度动画轻松做到这一点
export const buttonStateTrigger = trigger('buttonState', [
state('valid', style({
backgroundColor: 'lightgreen',
borderColor: 'green',
color: 'green'
})),
state('invalid', style({
backgroundColor: 'red',
borderColor: 'darkred',
color: 'white'
})),
transition('invalid => valid', [
group([
animate(100, style({
transform : 'scale(1.1)'
})),
animate(200, style({
backgroundColor: 'lightgreen'
})),
animate(200, style({
transform : 'scale(1)'
})),
])
]),
transition('valid => invalid', [
group([
animate(100, style({
transform : 'scale(1.1)'
})),
animate(200, style({
backgroundColor: 'red'
})),
animate(200, style({
transform : 'scale(1)'
})),
])
])
]);
你需要导入像这样的欲望组件
animations: [
buttonStateTrigger
]
HTML
`
<button
type="submit"
[disabled]="!f.valid"
[@buttonState]="f.valid ? 'valid' : 'invalid' "
class="btn btn-success">Create Project</button>
`
** 请启用角度动画 **
你可以关注我的项目https://github.com/ShahinAlKabirMitul/AngularStyling