mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-22 15:32:16 +01:00
Mind offset for top navigation bar on scrolling
This fixes the issue, that links to anchor tags in markdown documents have been scrolled a bit too far, so that the targeted element ended up below the navigation bar. Now, the height of the navigation bar is taken into account. Pushed-by: Rene Pfeuffer<rene.pfeuffer@cloudogu.com> Co-authored-by: Thomas Zerr<thomas.zerr@cloudogu.com> Pushed-by: Thomas Zerr<thomas.zerr@cloudogu.com> Co-authored-by: René Pfeuffer<rene.pfeuffer@cloudogu.com> Committed-by: René Pfeuffer<rene.pfeuffer@cloudogu.com>
This commit is contained in:
2
gradle/changelog/mind_header_when_scrolling.yaml
Normal file
2
gradle/changelog/mind_header_when_scrolling.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
- type: fixed
|
||||
description: The height of the navigation bar is now considered when scrolling to an element via anchor
|
||||
@@ -40,9 +40,12 @@ const useScrollToElement = (
|
||||
} else {
|
||||
tries++;
|
||||
const element = contentRef.querySelector(elementSelector);
|
||||
if (element && element.scrollIntoView) {
|
||||
if (element) {
|
||||
const headerElement = document.querySelector(".navbar-brand");
|
||||
const margin = headerElement ? headerElement.getBoundingClientRect().height : 45;
|
||||
clearInterval(intervalId);
|
||||
element.scrollIntoView();
|
||||
const y = element.getBoundingClientRect().top + window.pageYOffset - margin;
|
||||
window.scrollTo({top: y});
|
||||
}
|
||||
}
|
||||
}, 200);
|
||||
|
||||
Reference in New Issue
Block a user