Are there any polyfill available for angular 2 position:sticky. I have been able to find a few, but most of them are jquery based, there seem to be no implementation available for angular 2:
https://github.com/wilddeer/stickyfill
I need to know the sample usage with angular 2,
for Javascript it is as follows:
var stickyElements = document.getElementsByClassName('sticky');
for (var i = stickyElements.length - 1; i >= 0; i--) {
Stickyfill.add(stickyElements[i]);
}
Sticky Element Has Parent(s) with overflow PropertyIf the sticky element has a parent or ancestor with overflow: hidden , overflow: auto , or overflow: scroll , then position: sticky will not work properly.
Stickyfill is a polyfill. This means that it implements a feature (sticky positioning in this case) that already exists in some browsers natively, and allows to use this feature in the browsers that don't support it yet and older versions of the browsers that didn't support it at the time. This is its only purpose.
I added it as a directive on angular 1.4 and npm package "stickyfilljs":"^2.0.3"
import { Directive, ElementRef } from '@angular/core';
import * as Stickyfill from 'stickyfilljs';
@Directive({
selector: '[StickyPolyfill]'
})
export class StickyPolyfillDirective {
constructor(private elementRef: ElementRef) { }
ngAfterViewInit() {
Stickyfill.addOne(this.elementRef.nativeElement);
}
}
And in the component I have:
<div class="top-bar-container stickyMenu" StickyPolyfill>
Don't forget to include sticky in CSS:
.stickyMenu {
position: -webkit-sticky;
position: -moz-sticky;
position: -o-sticky;
position: -ms-sticky;
position: sticky;
top: 0px;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With