Improve side-menu sync

This commit is contained in:
Roman Gotsiy 2015-10-30 11:44:40 +02:00
parent 7783d8dc17
commit e6a1fde2e4

View File

@ -103,6 +103,7 @@ export default class SideMenu extends BaseComponent {
changeActive(offset = 1) { changeActive(offset = 1) {
let [catIdx, methodIdx] = this._calcActiveIndexes(offset); let [catIdx, methodIdx] = this._calcActiveIndexes(offset);
this.activate(catIdx, methodIdx); this.activate(catIdx, methodIdx);
return (methodIdx === 0 && catIdx === 0);
} }
getMethodEl() { getMethodEl() {
@ -115,16 +116,20 @@ export default class SideMenu extends BaseComponent {
scrollHandler() { scrollHandler() {
let isScrolledDown = (window.scrollY - this.prevOffsetY > 0); let isScrolledDown = (window.scrollY - this.prevOffsetY > 0);
this.prevOffsetY = window.scrollY; this.prevOffsetY = window.scrollY;
var activeMethodHost = this.getMethodEl(); let stable = false;
if (!activeMethodHost) return; while(!stable) {
let activeMethodHost = this.getMethodEl();
if (!activeMethodHost) return;
if(isScrolledDown && activeMethodHost.getBoundingClientRect().bottom <= 0 ) { if(isScrolledDown && activeMethodHost.getBoundingClientRect().bottom <= 0 ) {
this.changeActive(CHANGE.NEXT); stable = this.changeActive(CHANGE.NEXT);
return; continue;
} }
if(!isScrolledDown && activeMethodHost.getBoundingClientRect().top > 0 ) { if(!isScrolledDown && Math.floor(activeMethodHost.getBoundingClientRect().top) > 0 ) {
this.changeActive(CHANGE.BACK); stable = this.changeActive(CHANGE.BACK);
return; continue;
}
stable = true;
} }
} }