Skip to content

Commit

Permalink
fix(anchor-scroll): scroll inside nextTick (nuxt-modules#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz authored Feb 24, 2021
1 parent 5280262 commit c516288
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions theme/components/templates/Toc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ export default {
const hash = window.location.hash.replace('#', '')
const hashIndex = this.sections.findIndex(section => section.id === hash)
if (hash && hashIndex >= 0) {
scrollTo(0, document.querySelector(location.hash).offsetTop - 110) // 110 is the deafult value for `top-margin-scroll` in tailwind prose
this.setActive(hashIndex)
const offset = document.querySelector(location.hash).offsetTop - 110 // 110 is the deafult value for `top-margin-scroll` in tailwind prose
this.$nextTick().then(() => {
scrollTo(0, offset)
this.setActive(hashIndex)
})
} else {
this.onScroll()
}
Expand Down

0 comments on commit c516288

Please sign in to comment.