vue-markdown
vue-markdown copied to clipboard
hash模式下怎么使用toc进行锚点定位?/How to use hash mode TOC anchor position?
hash模式下怎么使用toc进行锚点定位? How to use hash mode TOC anchor position?
Something like this
document.addEventListener("click", handler, true)
function handler(e) {
if (e.target.tagName == 'A') {
if ((e.target.parentNode.parentNode.classList.contains('tocAnchors')) || (e.target.parentNode.parentNode.parentNode.parentNode.classList.contains('tocAnchors'))) {
e.stopPropagation(e.target.pathname)
e.preventDefault()
let anchorLink = document.getElementsByClassName('toc-anchor')
for (let i of anchorLink) {
if (i.hash === e.target.hash) {
i.scrollIntoView()
}
}
return
}
}