mirror of
https://github.com/Redocly/redoc.git
synced 2025-01-30 17:44:07 +03:00
Improve side-menu sync
This commit is contained in:
parent
7783d8dc17
commit
e6a1fde2e4
|
@ -103,6 +103,7 @@ export default class SideMenu extends BaseComponent {
|
|||
changeActive(offset = 1) {
|
||||
let [catIdx, methodIdx] = this._calcActiveIndexes(offset);
|
||||
this.activate(catIdx, methodIdx);
|
||||
return (methodIdx === 0 && catIdx === 0);
|
||||
}
|
||||
|
||||
getMethodEl() {
|
||||
|
@ -115,16 +116,20 @@ export default class SideMenu extends BaseComponent {
|
|||
scrollHandler() {
|
||||
let isScrolledDown = (window.scrollY - this.prevOffsetY > 0);
|
||||
this.prevOffsetY = window.scrollY;
|
||||
var activeMethodHost = this.getMethodEl();
|
||||
if (!activeMethodHost) return;
|
||||
let stable = false;
|
||||
while(!stable) {
|
||||
let activeMethodHost = this.getMethodEl();
|
||||
if (!activeMethodHost) return;
|
||||
|
||||
if(isScrolledDown && activeMethodHost.getBoundingClientRect().bottom <= 0 ) {
|
||||
this.changeActive(CHANGE.NEXT);
|
||||
return;
|
||||
}
|
||||
if(!isScrolledDown && activeMethodHost.getBoundingClientRect().top > 0 ) {
|
||||
this.changeActive(CHANGE.BACK);
|
||||
return;
|
||||
if(isScrolledDown && activeMethodHost.getBoundingClientRect().bottom <= 0 ) {
|
||||
stable = this.changeActive(CHANGE.NEXT);
|
||||
continue;
|
||||
}
|
||||
if(!isScrolledDown && Math.floor(activeMethodHost.getBoundingClientRect().top) > 0 ) {
|
||||
stable = this.changeActive(CHANGE.BACK);
|
||||
continue;
|
||||
}
|
||||
stable = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user