-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix page 'scroll to element' behaviour when URL hash is present
- Loading branch information
1 parent
3dc85f1
commit 1d3256a
Showing
4 changed files
with
54 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import AlpineComponent from "@js/alpine/component"; | ||
|
||
export default AlpineComponent("page", () => { | ||
return { | ||
init() { | ||
setTimeout(() => this.scrollToTarget(), 1); | ||
}, | ||
|
||
scrollToTarget() { | ||
if (location.hash?.startsWith("#")) { | ||
const scrollTarget = this.$root.querySelector(location.hash); | ||
if (scrollTarget) { | ||
scrollTarget.scrollIntoView({ behavior: "smooth" }); | ||
} | ||
} | ||
}, | ||
}; | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.