From a8d98b127be770063ea5ac199f3c550a0943eb75 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 31 Aug 2016 23:34:14 +0300 Subject: [PATCH] Fixed side menu overlapped site footer (#75) --- .../StickySidebar/sticky-sidebar.ts | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/shared/components/StickySidebar/sticky-sidebar.ts b/lib/shared/components/StickySidebar/sticky-sidebar.ts index 9482697e..5fb15a20 100644 --- a/lib/shared/components/StickySidebar/sticky-sidebar.ts +++ b/lib/shared/components/StickySidebar/sticky-sidebar.ts @@ -32,11 +32,24 @@ export class StickySidebar implements OnInit, OnDestroy { } updatePosition() { + var stuck = false; if ( this.scrollY + this.scrollYOffset() >= this.$redocEl.offsetTop) { this.stick(); + stuck = true; } else { this.unstick(); } + + if ( this.scrollY + window.innerHeight - this.scrollYOffset() >= this.$redocEl.scrollHeight) { + this.stickBottom(); + stuck = true; + } else { + this.unstickBottom(); + } + + if (!stuck) { + DOM.setStyle(this.$element, 'position', 'absolute'); + } } stick() { @@ -45,19 +58,33 @@ export class StickySidebar implements OnInit, OnDestroy { } unstick() { - DOM.setStyle(this.$element, 'position', 'absolute'); DOM.setStyle(this.$element, 'top', '0'); } + stickBottom() { + DOM.setStyle(this.$element, 'position', 'fixed'); + var offset = this.scrollY + this.scrollParentHeight - (this.$redocEl.scrollHeight + this.$redocEl.offsetTop); + DOM.setStyle(this.$element, 'bottom', offset + 'px'); + } + + unstickBottom() { + DOM.setStyle(this.$element, 'bottom', '0'); + } + get scrollY() { return (this.scrollParent.pageYOffset != undefined) ? this.scrollParent.pageYOffset : this.scrollParent.scrollTop; } + get scrollParentHeight() { + return (this.scrollParent.innerHeight != undefined) ? this.scrollParent.innerHeight : this.scrollParent.clientHeight; + } + ngOnInit() { // FIXME use more reliable code this.$redocEl = this.$element.offsetParent.parentNode || DOM.defaultDoc().body; this.bind(); - this.updatePosition(); + setTimeout(() => this.updatePosition()); + //this.updatePosition() } ngOnDestroy() {