Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 6ce05cf

Browse files
authored
fix(plugin-smooth-scroll): get target element by id or name (#58)
1 parent 549c900 commit 6ce05cf

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/vuepress-plugin-smooth-scroll/src/enhanceApp.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ const enhanceApp: EnhanceApp = ({ Vue, router }): void => {
3434
return
3535
}
3636

37-
const targetElement = document.querySelector(to.hash)
37+
const targetAnchor = to.hash.slice(1)
38+
const targetElement =
39+
document.getElementById(targetAnchor) ||
40+
document.querySelector(`[name='${targetAnchor}']`)
3841

3942
if (targetElement) {
4043
return window.scrollTo({

0 commit comments

Comments
 (0)