vue-markdown icon indicating copy to clipboard operation
vue-markdown copied to clipboard

hash模式下怎么使用toc进行锚点定位?/How to use hash mode TOC anchor position?

Open callmesoul opened this issue 8 years ago • 1 comments

hash模式下怎么使用toc进行锚点定位? How to use hash mode TOC anchor position?

callmesoul avatar May 13 '17 04:05 callmesoul

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
  }
}

Akirami avatar Nov 18 '17 16:11 Akirami