Fixed side menu overlapped site footer (#75)

This commit is contained in:
Roman Hotsiy 2016-08-31 23:34:14 +03:00
parent b649d52c39
commit a8d98b127b
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0

View File

@ -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() {