Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Commit

Permalink
Make the scrolling go the center of the screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
dj1ch committed Nov 14, 2023
1 parent faac30e commit e3e2815
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions components/FAQEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,10 @@ const entryRef = ref();
function scrollToEntry() {
const element = entryRef.value;
const questionElement = element.querySelector(".faq-question");
const rect = questionElement.getBoundingClientRect();
const yPosition = window.scrollY + rect.top - (window.innerHeight / 2 - rect.height / 2);
const adjustedPosition = Math.min(Math.max(yPosition, 0), document.documentElement.scrollHeight - window.innerHeight);
window.scrollTo({
top: adjustedPosition,
duration: 1000,
behavior: "smooth"
element.scrollIntoView({
behavior: "smooth",
block: "center",
inline: "center"
});
}
Expand Down Expand Up @@ -58,7 +52,7 @@ function onClick(ev) {
onMounted(() => {
if (window.location.hash) {
if (window.location.hash && window.history.state) {
checkIsActive();
scrollToEntry();
}
Expand Down

0 comments on commit e3e2815

Please sign in to comment.