mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-06 21:03:47 +02:00
fix(v2): unify anchor behavior (#2162)
* fix(v2): unify anchor behavior * fix(v2): use activeElement * fix(v2): add support for sticky header * Fix highlighted anchor if non-hidable navbar enabled
This commit is contained in:
parent
c0c0ad6661
commit
155539421b
4 changed files with 57 additions and 28 deletions
|
@ -21,13 +21,22 @@ const useHideableNavbar = hideOnScroll => {
|
|||
|
||||
const handleScroll = () => {
|
||||
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
||||
const documentHeight = document.documentElement.scrollHeight - navbarHeight;
|
||||
const windowHeight = window.innerHeight;
|
||||
|
||||
if (scrollTop < navbarHeight) {
|
||||
return;
|
||||
}
|
||||
|
||||
const focusedElement = document.activeElement;
|
||||
|
||||
if (focusedElement && /^#/.test(window.location.hash)) {
|
||||
setIsNavbarVisible(false);
|
||||
focusedElement.blur();
|
||||
return;
|
||||
}
|
||||
|
||||
const documentHeight = document.documentElement.scrollHeight - navbarHeight;
|
||||
const windowHeight = window.innerHeight;
|
||||
|
||||
if (lastScrollTop && scrollTop > lastScrollTop) {
|
||||
setIsNavbarVisible(false);
|
||||
} else if (scrollTop + windowHeight < documentHeight) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue