From b14374d609b79a61d91ce51eed2ec023ca46ad16 Mon Sep 17 00:00:00 2001 From: janschoenherr Date: Fri, 21 Sep 2018 12:11:30 +0200 Subject: [PATCH] perf: cleanup --- src/js/core/height-viewport.js | 14 +++++++------- src/js/core/sticky.js | 12 +++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/js/core/height-viewport.js b/src/js/core/height-viewport.js index 31db3f6379..89eef411b1 100644 --- a/src/js/core/height-viewport.js +++ b/src/js/core/height-viewport.js @@ -27,22 +27,22 @@ export default { read() { - const viewport = height(window); let minHeight = ''; if (this.expand) { - minHeight = viewport - (offsetHeight(document.documentElement) - offsetHeight(this.$el)) || ''; + minHeight = height(window) - (offsetHeight(document.documentElement) - offsetHeight(this.$el)) || ''; } else { - const {top} = offset(this.$el); - // on mobile devices (iOS and Android) window.innerHeight !== 100vh minHeight = 'calc(100vh'; - if (top < viewport / 2 && this.offsetTop) { - minHeight += ` - ${top}px`; + if (this.offsetTop) { + + const {top} = offset(this.$el); + minHeight += top < height(window) / 2 ? ` - ${top}px` : ''; + } if (this.offsetBottom === true) { @@ -67,7 +67,7 @@ export default { } - return {minHeight, viewport}; + return {minHeight}; }, write({minHeight}) { diff --git a/src/js/core/sticky.js b/src/js/core/sticky.js index 1214b95716..1aa2571b85 100644 --- a/src/js/core/sticky.js +++ b/src/js/core/sticky.js @@ -135,19 +135,17 @@ export default { read() { return { - height: this.$el.offsetHeight, - top: offset(this.isActive ? this.placeholder : this.$el).top + top: offset(this.isActive ? this.placeholder : this.$el).top, + height: css(this.$el, 'position') !== 'absolute' ? this.$el.offsetHeight : '', + margins: css(this.$el, ['marginTop', 'marginBottom', 'marginLeft', 'marginRight']) }; }, - write({height, top}) { + write({height, top, margins}) { const {placeholder} = this; - css(placeholder, assign( - {height: css(this.$el, 'position') !== 'absolute' ? height : ''}, - css(this.$el, ['marginTop', 'marginBottom', 'marginLeft', 'marginRight']) - )); + css(placeholder, assign({height}, margins)); if (!within(placeholder, document)) { after(this.$el, placeholder);