Skip to content

Instantly share code, notes, and snippets.

@theely
Last active September 13, 2017 19:23
Show Gist options
  • Save theely/a15b682809d3bddbf088e0198854e61a to your computer and use it in GitHub Desktop.
Save theely/a15b682809d3bddbf088e0198854e61a to your computer and use it in GitHub Desktop.
A angular2 component skeleton to implement a section sticky header
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