FIX: header offset position was not correct in some cases (#18155)

When a topic is opened in a new tab and is fully loaded the scroll
position is a bit off.

This commit partially reverts 9a55c9c433.
This commit is contained in:
Arpit Jalan 2022-09-19 18:26:34 +05:30 committed by GitHub
parent 754ad42344
commit ce27dbd560
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 0 deletions

View File

@ -177,6 +177,19 @@ const SiteHeaderComponent = MountWidget.extend(
this.docAt = header.offsetTop;
}
const headerRect = header.getBoundingClientRect();
let headerOffsetCalc = headerRect.top + headerRect.height;
if (window.scrollY < 0) {
headerOffsetCalc += window.scrollY;
}
const newValue = `${headerOffsetCalc}px`;
if (newValue !== this.currentHeaderOffsetValue) {
this.currentHeaderOffsetValue = newValue;
document.documentElement.style.setProperty("--header-offset", newValue);
}
const main = document.querySelector(".ember-application");
const offsetTop = main ? main.offsetTop : 0;
const offset = window.pageYOffset - offsetTop;