diff --git a/app/assets/javascripts/discourse/lib/offset-calculator.js.es6 b/app/assets/javascripts/discourse/lib/offset-calculator.js.es6 index 3c2fc1fc71..81e97e97dd 100644 --- a/app/assets/javascripts/discourse/lib/offset-calculator.js.es6 +++ b/app/assets/javascripts/discourse/lib/offset-calculator.js.es6 @@ -36,8 +36,12 @@ export default function offsetCalculator(y) { if (inter > ideal) { const bottom = $('#topic-bottom').offset().top; const switchPos = bottom - rawWinHeight; + if (scrollPercent >= 1.0) { + return 0; + } + if (scrollTop > switchPos) { - const p = Math.max(Math.min((scrollTop + inter - switchPos) / bottom, 1.0), 0.0); + const p = Math.max(Math.min((scrollTop + inter - switchPos) / rawWinHeight, 1.0), 0.0); return ((1 - p) * ideal) + (p * inter); } else { return ideal;