mirror of
https://github.com/youzan/vant.git
synced 2025-10-21 11:17:41 +00:00
fix(Indexbar): fix some bugs (#5012)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user