mirror of
https://github.com/youzan/vant.git
synced 2025-10-20 18:54:24 +00:00
[bugfix] IndexBar: activeAnchor bug fixes (#3832)
修复 sticky 设为 false 时activeAnchor失效的bug; 修复 this.scroller 不为 window 时activeAnchor错乱的bug;
This commit is contained in:
@@ -77,11 +77,9 @@ export default createComponent({
|
||||
|
||||
methods: {
|
||||
onScroll() {
|
||||
if (!this.sticky) {
|
||||
return;
|
||||
}
|
||||
|
||||
const scrollTop = getScrollTop(this.scroller);
|
||||
const scrollTop = this.scroller === window
|
||||
? getScrollTop(this.scroller)
|
||||
: 0;
|
||||
const rects = this.children.map(item => ({
|
||||
height: item.height,
|
||||
top: getElementTop(item.$el)
|
||||
@@ -90,18 +88,21 @@ export default createComponent({
|
||||
const active = this.getActiveAnchorIndex(scrollTop, rects);
|
||||
|
||||
this.activeAnchorIndex = this.indexList[active];
|
||||
this.children.forEach((item, index) => {
|
||||
if (index === active) {
|
||||
item.active = true;
|
||||
item.top = Math.max(this.stickyOffsetTop, rects[index].top - scrollTop);
|
||||
} else if (index === active - 1) {
|
||||
const activeItemTop = rects[active].top - scrollTop;
|
||||
item.active = activeItemTop > 0;
|
||||
item.top = activeItemTop - item.height;
|
||||
} else {
|
||||
item.active = false;
|
||||
}
|
||||
});
|
||||
|
||||
if (this.sticky) {
|
||||
this.children.forEach((item, index) => {
|
||||
if (index === active) {
|
||||
item.active = true;
|
||||
item.top = Math.max(this.stickyOffsetTop, rects[index].top - scrollTop);
|
||||
} else if (index === active - 1) {
|
||||
const activeItemTop = rects[active].top - scrollTop;
|
||||
item.active = activeItemTop > 0;
|
||||
item.top = activeItemTop - item.height;
|
||||
} else {
|
||||
item.active = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
getActiveAnchorIndex(scrollTop, rects) {
|
||||
|
Reference in New Issue
Block a user