Skip to content

Instantly share code, notes, and snippets.

@MarJaysonSanAgustin
Created December 7, 2017 08:01
Show Gist options
  • Save MarJaysonSanAgustin/40a3e82ad51e42fce93383818773f5c8 to your computer and use it in GitHub Desktop.
Save MarJaysonSanAgustin/40a3e82ad51e42fce93383818773f5c8 to your computer and use it in GitHub Desktop.
import { Directive, Input, ElementRef, Renderer } from '@angular/core';
/**
* Generated class for the HideHeaderDirective directive.
*
* See https://angular.io/docs/ts/latest/api/core/index/DirectiveMetadata-class.html
* for more info on Angular Directives.
*/
@Directive({
selector: '[hide-header]', // Attribute selector
host: {
'(ionScroll)': 'onContentScroll($event)'
}
})
export class HideHeaderDirective {
@Input("header") header: HTMLElement;
headerHeight;
scrollContent;
constructor(public element: ElementRef, public renderer: Renderer) {
console.log('Hello HideHeaderDirective Directive');
}
ngOnInit(){
this.headerHeight = this.header.clientHeight;
this.renderer.setElementStyle(this.header, 'webkitTransition', 'top 700ms');
this.scrollContent = this.element.nativeElement.getElementsByClassName("scroll-content")[0];
this.renderer.setElementStyle(this.scrollContent, 'webkitTransition', 'margin-top 700ms');
}
onContentScroll(event){
if(event.scrollTop > 56){
this.renderer.setElementStyle(this.header, "top", "-56px")
this.renderer.setElementStyle(this.scrollContent, "margin-top", "0px")
} else {
this.renderer.setElementStyle(this.header, "top", "0px");
this.renderer.setElementStyle(this.scrollContent, "margin-top", "56px")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment