【发布时间】:2019-10-02 17:39:41
【问题描述】:
我正在使用 @angular/animations 在 Ionic (v4) 上的两个页面之间设置页面转换,这一切都适用于 chrome,但不适用于 safari。
在一个只有两个页面(急切加载)的简单应用程序上,我仍然遇到问题,与我尝试设置动画的属性无关。如果我创建一个空动画,闪烁只会消失,但这不是目标。另外,我正在使用急切加载。
动画.ts
export const fadeIn =
trigger('fadeIn', [
state('entering', style({ //styles to be transitioned
opacity: 1,
})),
transition("* => entering", [ //this styles will enter before the animation starts
style({
opacity: 0,
display: block
}),
animate('500ms')
]),
state('leaving', style({ //this styles will enter when the animation ends
opacity: 0,
display: none
})),
transition("* => leaving", [ //styles to be transitioned
animate('220ms', style({
opacity: 0,
}))
]),
page1.ts
...
anim = ''
import { fadeIn } from '../animations/animations'
import { Router } from '@angular/router'
...
@Component({
selector: 'page-1',
templateUrl: './page1.html',
styleUrls: ['./page1.scss'],
animations: [ fadeIn ]
})
constructor(private router: Router){ }
ionViewWillEnter(){
this.anim = 'entering'
}
nextPage(){
this.router.navigate(['/page2'])
}
page2.ts
...
import { fadeIn } from '../animations/animations'
import { Router } from '@angular/router'
...
anim = ''
@Component({
selector: 'page-2',
templateUrl: './page2.html',
styleUrls: ['./page2.scss'],
animations: [ fadeIn ]
})
constructor(private router: Router){ }
ionViewWillEnter(){
this.anim = 'entering'
}
previousPage(){
this.anim = 'leaving'
setTimeout(() => {
this.router.navigate(['/page1'])
}, 200) //220 is the actual time to the transition end, but 200 to make sure that the blinking is not by an 'empty animation state'
}
page1.html
<ion-content [@fadeIn]='anim'>
<h1> This is the first page!
</ion-content>
page2.html
<ion-content [@fadeIn]='anim'>
<h1> This is the second page!
</ion-content>
page1.scss 和 page2.scss
ion-content{
display: none;
opacity: 0;
}
global.scss
@import "~@ionic/angular/css/core.css";
html > body > app-root > ion-app > ion-router-outlet > .ion-page-hidden {
display: flex !important;
}
...
为了更好地说明问题,我用慢动作记录下来并上传到Giphy
我希望在 safari 上的 chrome 上得到相同的结果,即使用这种动画结构而不在页面之间闪烁
【问题讨论】:
-
如果将动画(和自定义 css 规则)应用到
ion-content而不是内部div会发生什么?我认为您的动画可能与 Ionic 从一页导航到另一页时使用的动画冲突... -
在 ion-content 中动画效果很好。我认为您的猜测是正确的,但是您认为我可以覆盖默认动画吗?我已经尝试将 animated=false 放在 ion-router-outlet 上。
-
做
<ion-router-outlet main animated="false"></ion-router-outlet>没用? -
是的,没用
-
您使用的是哪个版本的 Ionic?你介意更新到
4.4吗?