From e6a1fde2e47bb4ba447fd440b817e8603fea317e Mon Sep 17 00:00:00 2001 From: Roman Gotsiy Date: Fri, 30 Oct 2015 11:44:40 +0200 Subject: [PATCH] Improve side-menu sync --- lib/components/SideMenu/side-menu.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/components/SideMenu/side-menu.js b/lib/components/SideMenu/side-menu.js index 75a89e43..e49f451e 100644 --- a/lib/components/SideMenu/side-menu.js +++ b/lib/components/SideMenu/side-menu.js @@ -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; } }