fix(IndexBar): fix the problem of rolling out parent boundaries when sucking bottom (#4218)

This commit is contained in:
流采
2019-08-24 16:01:55 +08:00
committed by neverland
parent a05a03b8b2
commit 689a579503
3 changed files with 22 additions and 8 deletions

View File

@@ -96,16 +96,28 @@ export default createComponent({
this.activeAnchorIndex = this.indexList[active];
if (this.sticky) {
let activeItemTop = 0;
let isReachEdge = false;
if (active !== -1) {
activeItemTop = rects[active].top - scrollTop;
isReachEdge = activeItemTop <= 0;
}
this.children.forEach((item, index) => {
if (index === active) {
item.active = true;
item.top = Math.max(this.stickyOffsetTop, rects[index].top - scrollTop) + scrollerRect.top;
item.position = isReachEdge ? 'fixed' : 'relative';
item.top = isReachEdge
? this.stickyOffsetTop + scrollerRect.top
: 0;
} else if (index === active - 1) {
const activeItemTop = rects[active].top - scrollTop;
item.active = activeItemTop > 0;
item.top = activeItemTop + scrollerRect.top - item.height;
item.active = !isReachEdge;
item.position = 'relative';
item.top = item.$el.parentElement.offsetHeight - item.height;
} else {
item.active = false;
item.position = 'static';
}
});
}