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);