UNPKG

ngx-auto-scroll

Version:

Angular 2+ directive to automatically scroll html container content to the bottom.

103 lines (98 loc) 2.52 kB
import { Directive, ElementRef, HostListener, Input, NgModule } from '@angular/core'; class NgxAutoScroll { /** * @param {?} element */ constructor(element) { this.lockYOffset = 10; this.observeAttributes = "false"; this._isLocked = false; this.nativeElement = element.nativeElement; } /** * @return {?} */ getObserveAttributes() { return this.observeAttributes !== "" && this.observeAttributes.toLowerCase() !== "false"; } /** * @return {?} */ ngAfterContentInit() { this.mutationObserver = new MutationObserver(() => { if (!this._isLocked) { this.scrollDown(); } }); this.mutationObserver.observe(this.nativeElement, { childList: true, subtree: true, attributes: this.getObserveAttributes(), }); } /** * @return {?} */ ngOnDestroy() { this.mutationObserver.disconnect(); } /** * @return {?} */ forceScrollDown() { this.scrollDown(); } /** * @return {?} */ isLocked() { return this._isLocked; } /** * @return {?} */ scrollDown() { this.nativeElement.scrollTop = this.nativeElement.scrollHeight; } /** * @return {?} */ scrollHandler() { const /** @type {?} */ scrollFromBottom = this.nativeElement.scrollHeight - this.nativeElement.scrollTop - this.nativeElement.clientHeight; this._isLocked = scrollFromBottom > this.lockYOffset; } } NgxAutoScroll.decorators = [ { type: Directive, args: [{ selector: "[ngx-auto-scroll]", },] }, ]; /** * @nocollapse */ NgxAutoScroll.ctorParameters = () => [ { type: ElementRef, }, ]; NgxAutoScroll.propDecorators = { 'lockYOffset': [{ type: Input, args: ["lock-y-offset",] },], 'observeAttributes': [{ type: Input, args: ["observe-attributes",] },], 'scrollHandler': [{ type: HostListener, args: ["scroll",] },], }; class NgxAutoScrollModule { } NgxAutoScrollModule.decorators = [ { type: NgModule, args: [{ declarations: [NgxAutoScroll], imports: [], exports: [NgxAutoScroll] },] }, ]; /** * @nocollapse */ NgxAutoScrollModule.ctorParameters = () => []; /** * Generated bundle index. Do not edit. */ export { NgxAutoScroll, NgxAutoScrollModule }; //# sourceMappingURL=ngx-auto-scroll.js.map