Skip to content

Commit

Permalink
Added offset when task is scrolled to prevent menu overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
talentedunicorn committed Jan 28, 2024
1 parent 5b7dbbb commit ad6b263
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/components/Task.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,19 @@
const scrollToID = (ev: MouseEvent) => {
ev.preventDefault();
const offset = document.querySelector('.Menu')?.getBoundingClientRect().height ?? 0; // Set offset so menu doesn't cover the task
const el = ev.currentTarget as HTMLLinkElement;
const id = el.getAttribute('href')?.slice(0);
const scrollTo = document.querySelector(id!);
const target = document.querySelector(id!);
const bodyPosition = document.body.getBoundingClientRect().top;
const targetPosition = target?.getBoundingClientRect().top ?? 0;
scrollTo?.scrollIntoView({ behavior: 'smooth' });
const top = targetPosition - bodyPosition - offset;
// Wait for CSS expanded class to be applied
setTimeout(() => {
window.scrollTo({ top, behavior: 'smooth' });
}, 300);
};
const scrollIntoView = (el: HTMLAnchorElement) => {
Expand Down

0 comments on commit ad6b263

Please sign in to comment.