Zoeken...  ⌘K GitHub

ContentTimeline content

Alternerende tijdlijn met centrale lijn die vult bij scrollen. Jaar-labels op de knooppunten. Ideaal voor bedrijfshistorie of roadmap.

/content-timeline
src/components/content/ContentTimeline.astro
---
interface TimelineItem {
  year: string;
  title: string;
  description: string;
  image?: string;
}

interface Props {
  eyebrow?: string;
  headline?: string;
  items: TimelineItem[];
}

const { eyebrow, headline, items = [] } = Astro.props;
---

<section class="ctl__section">
  {(eyebrow || headline) && (
    <div class="ctl__header">
      {eyebrow && <p class="ctl__eyebrow">{eyebrow}</p>}
      {headline && <h2 class="ctl__headline">{headline}</h2>}
    </div>
  )}

  <div class="ctl__timeline" role="list">
    <!-- Central line -->
    <div class="ctl__line" aria-hidden="true">
      <div class="ctl__line-fill" id="ctl-line-fill"></div>
    </div>

    {items.map((item, i) => {
      const isLeft = i % 2 === 0;
      return (
        <div
          class={`ctl__item${isLeft ? ' ctl__item--left' : ' ctl__item--right'}`}
          data-index={i}
          role="listitem"
        >
          <!-- Left slot -->
          <div class="ctl__slot ctl__slot--left">
            {isLeft && (
              <div class="ctl__card ctl__card--left ctl-card">
                {item.image && (
                  <div class="ctl__card-img-wrap">
                    <img src={item.image} alt="" class="ctl__card-img" loading="lazy" decoding="async" />
                  </div>
                )}
                <h3 class="ctl__card-title">{item.title}</h3>
                <p class="ctl__card-desc">{item.description}</p>
              </div>
            )}
          </div>

          <!-- Center node -->
          <div class="ctl__node-wrap" aria-hidden="true">
            <div class="ctl__node">
              <span class="ctl__year">{item.year}</span>
            </div>
          </div>

          <!-- Right slot -->
          <div class="ctl__slot ctl__slot--right">
            {!isLeft && (
              <div class="ctl__card ctl__card--right ctl-card">
                {item.image && (
                  <div class="ctl__card-img-wrap">
                    <img src={item.image} alt="" class="ctl__card-img" loading="lazy" decoding="async" />
                  </div>
                )}
                <h3 class="ctl__card-title">{item.title}</h3>
                <p class="ctl__card-desc">{item.description}</p>
              </div>
            )}
          </div>
        </div>
      );
    })}
  </div>
</section>

<script>
  // Card reveal observer
  const cards = document.querySelectorAll<HTMLElement>('.ctl-card');

  const cardObserver = new IntersectionObserver(
    (entries) => {
      entries.forEach((entry) => {
        if (entry.isIntersecting) {
          (entry.target as HTMLElement).classList.add('ctl-card--visible');
          cardObserver.unobserve(entry.target);
        }
      });
    },
    { threshold: 0.2 }
  );

  cards.forEach((card) => cardObserver.observe(card));

  // Line fill via scroll
  const lineFill = document.getElementById('ctl-line-fill');
  const timeline = document.querySelector<HTMLElement>('.ctl__timeline');

  if (lineFill && timeline) {
    const updateLine = () => {
      const rect = timeline.getBoundingClientRect();
      const viewportH = window.innerHeight;

      // How far we've scrolled into the timeline
      const scrolled = Math.max(0, viewportH - rect.top);
      const total = rect.height + viewportH;
      const progress = Math.min(1, scrolled / total);

      lineFill.style.transform = `scaleY(${progress})`;
    };

    window.addEventListener('scroll', updateLine, { passive: true });
    updateLine();
  }
</script>

<style>
  :root {
    --color-primary: #0a0a0a;
    --color-accent: #6366f1;
    --color-bg: #fff;
    --color-muted: #6b7280;
    --radius: 0.5rem;
  }

  .ctl__section {
    background: var(--color-bg);
    padding: clamp(3rem, 8vw, 7rem) clamp(1rem, 5vw, 2rem);
  }

  .ctl__header {
    text-align: center;
    max-width: 720px;
    margin: 0 auto clamp(3rem, 5vw, 5rem);
  }

  .ctl__eyebrow {
    font-size: clamp(0.65rem, 1.2vw, 0.75rem);
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--color-accent);
    margin: 0 0 0.75rem;
  }

  .ctl__headline {
    font-size: clamp(1.75rem, 3vw, 2.75rem);
    font-weight: 800;
    line-height: 1.2;
    color: var(--color-primary);
    margin: 0;
  }

  /* Timeline grid */
  .ctl__timeline {
    position: relative;
    max-width: 1100px;
    margin: 0 auto;
  }

  /* Central line */
  .ctl__line {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    background: rgba(0, 0, 0, 0.08);
    z-index: 0;
  }

  .ctl__line-fill {
    position: absolute;
    inset: 0;
    background: var(--color-accent);
    transform-origin: top center;
    transform: scaleY(0);
    transition: transform 0.1s linear;
    opacity: 0.35;
  }

  /* Each row */
  .ctl__item {
    display: grid;
    grid-template-columns: 1fr 60px 1fr;
    align-items: center;
    min-height: 120px;
    margin-bottom: clamp(2rem, 4vw, 3.5rem);
    position: relative;
    z-index: 1;
  }

  /* Slots */
  .ctl__slot {
    padding: 0 1.5rem;
  }

  .ctl__slot--left {
    display: flex;
    justify-content: flex-end;
  }

  .ctl__slot--right {
    display: flex;
    justify-content: flex-start;
  }

  /* Node */
  .ctl__node-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
  }

  .ctl__node {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--color-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
    position: relative;
    z-index: 2;
    flex-shrink: 0;
  }

  .ctl__year {
    font-size: 0.65rem;
    font-weight: 800;
    color: #fff;
    letter-spacing: 0.04em;
    white-space: nowrap;
  }

  /* Cards */
  .ctl__card {
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.07);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.05);
  }

  .ctl__card--left {
    text-align: right;
  }

  .ctl__card--right {
    text-align: left;
  }

  .ctl__card-img-wrap {
    margin-bottom: 0.875rem;
  }

  .ctl__card--left .ctl__card-img-wrap {
    display: flex;
    justify-content: flex-end;
  }

  .ctl__card-img {
    width: 100%;
    max-height: 160px;
    object-fit: cover;
    border-radius: calc(var(--radius) - 2px);
  }

  .ctl__card-title {
    font-size: clamp(1rem, 1.5vw, 1.125rem);
    font-weight: 700;
    color: var(--color-primary);
    margin: 0 0 0.5rem;
  }

  .ctl__card-desc {
    font-size: 0.9375rem;
    line-height: 1.65;
    color: var(--color-muted);
    margin: 0;
  }

  /* Scroll reveal — cards slide in from their side */
  .ctl-card {
    opacity: 0;
    transition: opacity 0.65s ease, transform 0.65s ease;
  }

  .ctl__card--left.ctl-card {
    transform: translateX(2rem);
  }

  .ctl__card--right.ctl-card {
    transform: translateX(-2rem);
  }

  .ctl-card--visible {
    opacity: 1;
    transform: translateX(0) !important;
  }

  /* Mobile: stack all left */
  @media (max-width: 680px) {
    .ctl__line {
      left: 22px;
    }

    .ctl__item {
      grid-template-columns: 60px 1fr;
      grid-template-rows: auto;
    }

    .ctl__slot--left {
      display: none;
    }

    .ctl__slot--right {
      grid-column: 2;
      grid-row: 1;
      justify-content: flex-start;
      padding: 0 0 0 1rem;
    }

    /* Items that had content on left now render on right */
    .ctl__item--left .ctl__slot--left {
      display: flex;
      grid-column: 2;
      grid-row: 1;
      justify-content: flex-start;
      padding: 0 0 0 1rem;
    }

    .ctl__item--left .ctl__card--left {
      text-align: left;
    }

    .ctl__node-wrap {
      grid-column: 1;
      grid-row: 1;
    }

    .ctl__card--left.ctl-card,
    .ctl__card--right.ctl-card {
      transform: translateY(1rem);
    }

    .ctl-card--visible {
      transform: translateY(0) !important;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    * {
      animation: none !important;
      transition: none !important;
    }
  }
</style>

Props

Prop Type Default Beschrijving
items * { year: string; title: string; description: string; image?: string }[] Tijdlijn items
eyebrow string Label boven sectie
headline string Sectie headline

* = verplicht