Demo:
generate directive
ionic g directive HideHeader
and copy below code in hide-header.ts file
import { Directive, Input, ElementRef, Renderer } from '@angular/core';
@Directive({
selector: '[hide-header]', // Attribute selector
host: {
'(ionScroll)': 'onContentScroll($event)'
}
})
export class HideHeaderDirective {
@Input("header") header: HTMLElement;
@Input("footer") footer: HTMLElement;
constructor(public element: ElementRef, public renderer: Renderer) {
console.log('Hello HideHeaderDirective Directive');
}
ngOnInit() {
this.renderer.setElementStyle(this.header, 'webkitTransition', 'top 700ms');
this.renderer.setElementStyle(this.footer, 'webkitTransition', 'bottom 700ms');
}
onContentScroll(event) {
if (event.directionY == "down") {
this.renderer.setElementStyle(this.header, 'top', '-56px');
this.renderer.setElementStyle(this.footer, 'bottom', '-56px');
}
else {
this.renderer.setElementStyle(this.header, 'top', '0px');
this.renderer.setElementStyle(this.footer, 'bottom', '0px');
}
}
}
and simply add directive to any header and footer in page
<ion-header #header>
<ion-navbar>
<ion-title>
Ionic Header
</ion-title>
</ion-navbar>
</ion-header>
<ion-content fullscreen hide-header [header]="header" [footer]="footer">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eum nam totam recusandae, iusto consequuntur quibusdam
aliquid voluptate, placeat qui explicabo optio facilis similique doloribus aperiam animi voluptas, unde repellat
sint?</p>
</ion-content>
<ion-footer #footer>
<ion-navbar>
<ion-title>
Ionic Footer
</ion-title>
</ion-navbar>
</ion-footer>
reference from : https://github.com/samarthagarwal/ScrollingHeader