vue项目锚点定位+滚动定位
文来自:https://blog.csdn.net/qq_43369797/article/details/98966790
功能:
HTML:
js:
scrollEvent(e) {let scrollItems = document.querySelectorAll(\'.condition-container\')
for (let i = scrollItems.length - 1; i >= 0; i--) {
// 判断滚动条滚动距离是否大于当前滚动项可滚动距离
let judge = e.target.scrollTop >= scrollItems[i].offsetTop - scrollItems[0].offsetTop
if (judge) {
this.activeClass = i
break
}
}
// 滚动条触底了
if (e.srcElement.scrollTop + e.srcElement.offsetHeight === e.srcElement.scrollHeight) {
this.activeClass = 4 - 1
}
},
getActiveClass(index) {
this.activeClass = index
let jump = document.querySelectorAll(\'.condition-container\')
jump[index].scrollIntoView({ block: \'start\', behavior: \'smooth\' })
}
以上是 vue项目锚点定位+滚动定位 的全部内容, 来源链接: utcz.com/z/377141.html