vue写鼠标点击锚点的一个笨方法

    const headingGroup = this.$refs.preview.$el.querySelectorAll('h1,h2,h3,h4,h5,h6')
    for (let i = 0; i < headingGroup.length; ++i) {
          if (headingGroup[i].innerText === (anchor.title)) { 
            headingGroup[i].scrollIntoView({
              behavior: 'smooth',
              block: 'start'
            })
           }

对于在vue里实现鼠标点击锚点功能 可以使用枚举

当点击某段标题时 可以直接调用上段代码 把浏览器焦点移到目标区域

对于访问NodeList方式:直接数组下标索引即可。

猜你喜欢

转载自blog.csdn.net/qq_33859479/article/details/130368366