From cb8f91ca215a5dc85a771b3691b334a89c54664a Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 27 Apr 2017 16:21:54 -0400 Subject: [PATCH] FIX: Scrolling offset was broken when entering some topics --- app/assets/javascripts/discourse/lib/lock-on.js.es6 | 2 +- app/assets/javascripts/discourse/lib/offset-calculator.js.es6 | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/lock-on.js.es6 b/app/assets/javascripts/discourse/lib/lock-on.js.es6 index 10c3542670e..23f7752ece4 100644 --- a/app/assets/javascripts/discourse/lib/lock-on.js.es6 +++ b/app/assets/javascripts/discourse/lib/lock-on.js.es6 @@ -35,7 +35,7 @@ export default class LockOn { const selected = $(this.selector); if (selected && selected.offset && selected.offset()) { const result = selected.offset().top; - return result - Math.round(scrollTopFor(result)); + return result - (Math.round(scrollTopFor(result)) * 0.9); } } diff --git a/app/assets/javascripts/discourse/lib/offset-calculator.js.es6 b/app/assets/javascripts/discourse/lib/offset-calculator.js.es6 index 8903f0ee173..84691d6a05d 100644 --- a/app/assets/javascripts/discourse/lib/offset-calculator.js.es6 +++ b/app/assets/javascripts/discourse/lib/offset-calculator.js.es6 @@ -25,7 +25,7 @@ export default function offsetCalculator(y) { const scrollTop = y || $(window).scrollTop(); const docHeight = $(document).height(); - const scrollPercent = (scrollTop / (docHeight-rawWinHeight)); + let scrollPercent = Math.min((scrollTop / (docHeight-rawWinHeight)), 1.0); let inter = topPos - scrollTop + ($container.height() * scrollPercent); if (inter < headerHeight + eyeTarget) { @@ -35,7 +35,7 @@ export default function offsetCalculator(y) { if (inter > ideal) { const bottom = $('#topic-bottom').offset().top; - const switchPos = bottom - rawWinHeight; + const switchPos = bottom - rawWinHeight - ideal; if (scrollTop > switchPos) { const p = Math.max(Math.min((scrollTop + inter - switchPos) / rawWinHeight, 1.0), 0.0);