Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: timeline scroll behavior #112

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/components/timeline/page/TimelinePageItem.svelte
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
<script lang="ts">
import { onMount } from 'svelte';
import { timelineColors } from '../colors';
import type { TimelineItem } from '../dataProcess/parse';

export let item: TimelineItem;

const colors = timelineColors[item.type] ?? timelineColors['default'];
const { bg, accent, border } = colors;

const isDefault = !Boolean(item.type);
const isMilestone = item.importance == '0';
console.log(item);

/* Scrolling behavior */

const anchorId = encodeURIComponent(item.title);
const anchor = window.location.hash.substring(1);
const isAnchor = anchorId == anchor;

let thisEl: HTMLDivElement;

onMount(() => {
if (!isAnchor) return;
const headerOffset = 45;
const elementPosition = thisEl.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.scrollY - headerOffset;

window.scrollTo({
top: offsetPosition,
behavior: 'smooth',
});
});
</script>

<div class="relative pl-6 font-sans" id={encodeURIComponent(item.title)}>
<div bind:this={thisEl} id={anchorId} class="relative pl-6 font-sans">
{#if item.restOfDate}
<div
class={`hidden md:block absolute top-0.5 -left-32 text-primary-light pr-2 w-28 text-right text-xl ${
Expand Down