【发布时间】:2017-03-28 01:19:33
【问题描述】:
我只想在页面滚动到特定点时显示我的ion-header
html
<ion-header *ngIf="headered"><!--use ngif to trigger-->
<ion-navbar>
some content
</ion-navbar>
</ion-header>
所以会通过滚动触发:
ts
import { ..., Content } from 'ionic-angular';
...
@ViewChild(Content) content:Content;
headered = false;
...
ngAfterViewInit() {
this.content.addScrollListener(this.onPageScroll);
}
onPageScroll(event) {
console.log(event.target.scrollTop);
if(event.target.scrollTop > 640){
this.headered = true;
console.log(this.headered);///<-- this did trigger when scroll more than 640
}else{
this.headered = false;
}
}
我确实在控制台中得到了true,但标题没有出现。我通过添加一个调用此函数的按钮再次对其进行测试:
toggleHeader(){
this.headered = (this.headered == false) ? true : false;
}
并且标题确实显示和隐藏了方面。
为什么滚动事件不能让标题显示?我该如何解决这个问题?
更新01
我试过了:
scrollCount = 0;
...
onPageScroll(event) {
this.scrollCount = event.target.scrollTop;
console.log(this.scrollCount);///<-- this give me reading
}
///then use ngDoCheck to detect:
ngDoCheck(){
console.log(this.scrollCount);///<-- this always get 0.
}
正如您在onPageScroll() 中看到的那样,我开始阅读,但我没有阅读。我怀疑它与@ViewChild(Content) content:Content; 有关,ionic2 在their doc 中建议。
【问题讨论】:
标签: javascript angular typescript ionic2