1
我需要在我的應用程序,其保持當前塊的值來創建一個粘性標題。離子2 - 置頂頭
import { Component, ViewChild } from '@angular/core';
import { Content } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
@ViewChild(Content)
content:Content;
ngAfterViewInit() {
// I want to trigger the listener during the scroll event
this.content.ionScroll.subscribe((data)=>{
this.onPageScroll(data);
});
}
onPageScroll(data) {
console.log("top:", data['scrollTop'])
}
:
:
爲了確定在粘頭要顯示的元素,我在各端框隱藏的元件:
<div class="titleTag" style="display:none">{{event.title}}</div>
我使用此代碼檢索滾動位置
當我嘗試檢索這些元素的位置:
let titleTags = document.getElementsByClassName('titleTag');
for (let el of <any>titleTags) {
console.log(" > offsetTop", el.offsetTop);
}
我得到0 。
我也offsetHeight
和scrollTop
嘗試,都返回0爲好。
任何想法?
您是否嘗試過''? https://ionicframework.com/docs/api/components/toolbar/Header/ –
Chris
我有一個''元素,它實際上有粘性標題佔位符,但問題是我不設法獲得下元素來顯示! –
guyaloni
爲sticky ion-list-header創建一個小指令:https://github.com/jonaszuberbuehler/ion-affix。你需要這樣嗎? – z00bs