Skip to content

Commit de04bb1

Browse files
authored
Merge pull request #218 from tidev/scrollFix
fix: anchor scroll
2 parents f99aa30 + 4ef4b59 commit de04bb1

File tree

1 file changed

+21
-0
lines changed
  • packages/vuepress/vuepress-theme-titanium/plugins/smoothScroll

1 file changed

+21
-0
lines changed

packages/vuepress/vuepress-theme-titanium/plugins/smoothScroll/enhanceApp.js

+21
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,32 @@ module.exports = ({ Vue, options, router }) => {
3434
behavior: 'smooth'
3535
})
3636
}
37+
window.onload = () => {
38+
const element = document.getElementById(location.hash.slice(1))
39+
if (element) {
40+
element.scrollIntoView()
41+
}
42+
}
3743
} else {
3844
const html = document.querySelector('html')
3945
html.style.scrollBehavior = 'auto'
4046
window.scrollTo({ top: 0 })
4147
html.style.scrollBehavior = ''
4248
}
49+
50+
if (location.hash) {
51+
setTimeout(function() {
52+
const element = document.getElementById(location.hash.slice(1))
53+
if (element) {
54+
element.scrollIntoView()
55+
}
56+
}, 250);
57+
}
58+
window.onload = () => {
59+
const element = document.getElementById(location.hash.slice(1))
60+
if (element) {
61+
element.scrollIntoView()
62+
}
63+
}
4364
}
4465
}

0 commit comments

Comments
 (0)