Skip to content

Commit

Permalink
fix(index-bar): fix bug of scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
BeADre committed Apr 20, 2021
1 parent 3155bf6 commit 872bc14
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/varlet-ui/src/index-bar/IndexBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,16 @@ export default defineComponent({
}
const handleScroll = () => {
const { scrollTop } = scrollEl.value as HTMLElement
const { scrollTop, scrollHeight } = scrollEl.value as HTMLElement
indexAnchors.forEach((anchor: IndexAnchorProvider, index: number) => {
const anchorTop = anchor.ownTop.value
const top = scrollTop - anchorTop + stickyOffsetTop.value
if (top >= 0 && top <= 10) {
emitEvent(anchor)
} else if (top < 0 && top >= -10) {
const preAnchor = indexAnchors[index - 1]
emitEvent(preAnchor)
}
const distance = index === indexAnchors.length - 1
? scrollHeight
: indexAnchors[index + 1].ownTop.value - anchor.ownTop.value
if (top >= 0 && top <= distance) emitEvent(anchor)
})
}
Expand Down Expand Up @@ -114,6 +113,7 @@ export default defineComponent({
return {
barEl,
active,
zIndex,
anchorNameList,
scrollTo,
anchorClick,
Expand Down

0 comments on commit 872bc14

Please sign in to comment.