Skip to content

A platform for community discussion. Free, open, simple.

FIX: include header offset relative to window (#11114)

Kris3ee216c036e6
diff --git a/app/assets/javascripts/discourse/app/lib/offset-calculator.js b/app/assets/javascripts/discourse/app/lib/offset-calculator.js
index c9cffee5cfd..9ce8c234e24 100644
--- a/app/assets/javascripts/discourse/app/lib/offset-calculator.js
+++ b/app/assets/javascripts/discourse/app/lib/offset-calculator.js
@@ -7,7 +7,14 @@ export function minimumOffset() {
iPadNav = document.querySelector(".footer-nav-ipad .footer-nav"),
iPadNavHeight = iPadNav ? iPadNav.offsetHeight : 0;
- return header ? header.offsetHeight + iPadNavHeight : 0;
+ // if the header has a positive offset from the top of the window, we need to include the offset
+ // this covers cases where a site has a custom header above d-header (covers fixed and unfixed)
+ const headerWrap = document.querySelector(".d-header-wrap"),
+ headerWrapOffset = headerWrap.getBoundingClientRect();
+
+ return header
+ ? header.offsetHeight + headerWrapOffset.top + iPadNavHeight
+ : 0;
}
export default function offsetCalculator() {