fix(Indexbar): fix some bugs (#5012)

This commit is contained in:
Fyerl
2019-11-14 17:48:37 +08:00
committed by neverland
parent 04df584a65
commit 7aee4fb9a2
2 changed files with 11 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ import { ParentMixin } from '../mixins/relation';
import { BindEventMixin } from '../mixins/bind-event';
import { GREEN } from '../utils/constant';
import { preventDefault } from '../utils/dom/event';
import { isHidden } from '../utils/dom/style';
import {
getScrollTop,
getElementTop,
@@ -85,6 +86,10 @@ export default createComponent({
methods: {
onScroll() {
if (isHidden(this.$el)) {
return;
}
const scrollTop = getScrollTop(this.scroller);
const scrollerRect = this.getScrollerRect();
const rects = this.children.map(item => ({
@@ -101,7 +106,7 @@ export default createComponent({
let isReachEdge = false;
if (active !== -1) {
activeItemTop = rects[active].top - scrollTop;
activeItemTop = rects[active].top - scrollTop - this.stickyOffsetTop;
isReachEdge = activeItemTop <= 0;
}
@@ -153,8 +158,9 @@ export default createComponent({
getActiveAnchorIndex(scrollTop, rects) {
for (let i = this.children.length - 1; i >= 0; i--) {
const prevHeight = i > 0 ? rects[i - 1].height : 0;
const reachTop = this.sticky ? prevHeight + this.stickyOffsetTop : 0;
if (scrollTop + prevHeight + this.stickyOffsetTop >= rects[i].top) {
if (scrollTop + reachTop >= rects[i].top) {
return i;
}
}
@@ -195,7 +201,7 @@ export default createComponent({
if (match[0]) {
match[0].scrollIntoView();
if (this.stickyOffsetTop) {
if (this.sticky && this.stickyOffsetTop) {
setRootScrollTop(getRootScrollTop() - this.stickyOffsetTop);
}