Last active
September 13, 2017 19:23
-
-
Save theely/a15b682809d3bddbf088e0198854e61a to your computer and use it in GitHub Desktop.
A angular2 component skeleton to implement a section sticky header
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Component, OnInit, ElementRef, Output, EventEmitter, HostListener,Input,Output } from '@angular/core'; | |
@Component({ | |
selector: 'section', | |
templateUrl: './section.component.html', | |
styleUrls: ['./section.component.css'] | |
}) | |
export class SectionComponent implements OnInit { | |
@Output() sectionPosition = new EventEmitter(); | |
@Input() content: Section; | |
constructor(private element: ElementRef) {} | |
ngOnInit() { | |
this.sectionPosition.emit({ name: this.content.name, position: this.element.nativeElement.offsetTop }); | |
} | |
@HostListener('window:resize', ['$event']) | |
onResize(event) { | |
this.sectionPosition.emit({ name: this.content.name, position: this.element.nativeElement.offsetTop }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment