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) {
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;
}
}