fix: 🐛 修复IndexBar点击索引序号时未显示预期索引值的问题

 Closes: #408
This commit is contained in:
weisheng 2024-07-07 23:24:53 +08:00
parent 4741439277
commit c33991ee14
2 changed files with 6 additions and 3 deletions

View File

@ -35,7 +35,7 @@ function getInfo() {
getRect(`#${indexAnchorId.value}`, false, proxy).then((res) => {
if (isDef(indexBar)) {
const anchor = indexBar.anchorState.anchorList.find((v) => v.index === props.index)!
anchor.top = res.top!
anchor.top = Math.floor(res.top!)
}
})
}

View File

@ -82,12 +82,15 @@ onMounted(() => {
function hanleScroll(scrollEvent: any) {
const { detail } = scrollEvent
const scrolltop = Math.floor(detail.scrollTop)
const anchor = state.anchorList.find((item, index) => {
if (!isDef(state.anchorList[index + 1])) return true
if (item.top - offsetTop <= detail.scrollTop && state.anchorList[index + 1].top - offsetTop > detail.scrollTop) return true
if (item.top - offsetTop <= scrolltop && state.anchorList[index + 1].top - offsetTop > scrolltop) return true
return false
})!
state.activeIndex = anchor.index
if (state.activeIndex !== anchor.index) {
state.activeIndex = anchor.index
}
}
function getAnchorByPageY(pageY: number) {