diff --git a/src/uni_modules/wot-design-uni/components/wd-index-anchor/wd-index-anchor.vue b/src/uni_modules/wot-design-uni/components/wd-index-anchor/wd-index-anchor.vue index 402a0765..67a808a3 100644 --- a/src/uni_modules/wot-design-uni/components/wd-index-anchor/wd-index-anchor.vue +++ b/src/uni_modules/wot-design-uni/components/wd-index-anchor/wd-index-anchor.vue @@ -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!) } }) } diff --git a/src/uni_modules/wot-design-uni/components/wd-index-bar/wd-index-bar.vue b/src/uni_modules/wot-design-uni/components/wd-index-bar/wd-index-bar.vue index 75de549e..3dd4412e 100644 --- a/src/uni_modules/wot-design-uni/components/wd-index-bar/wd-index-bar.vue +++ b/src/uni_modules/wot-design-uni/components/wd-index-bar/wd-index-bar.vue @@ -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) {