Created
June 26, 2026 15:21
-
-
Save mornir/2b5ac694e16dd47eb406386cd366af90 to your computer and use it in GitHub Desktop.
scrollspy
This file contains hidden or 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
| <h2 | |
| class="mb-3 scroll-mt-24" | |
| id={`art-${number}`} | |
| x-intersect:enter="$store.scrollSpy.activeId = 'art-'+number" | |
| > | |
| <span class="mb-1 block font-mono text-sm text-slate-600" | |
| >Artikel {number}</span | |
| > | |
| <a class="block text-xl font-semibold hover:underline" href={url}>{name}</a> | |
| </h2> |
This file contains hidden or 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
| <aside | |
| x-data | |
| x-init="$store.scrollSpy.activeId = window.location.hash.slice(1) || ''" | |
| x-effect="if ($store.scrollSpy.activeId) { const link = document.querySelector('aside[x-data] nav a[href=\'#' + $store.scrollSpy.activeId + '\']'); link?.scrollIntoView({ block: 'nearest', inline: 'nearest', behavior: 'smooth' }) }" | |
| class="sticky top-24 h-fit" | |
| > | |
| <p class="text-lg font-semibold mb-2">{title}</p> | |
| <nav class="flex flex-col gap-y-3 h-[calc(100vh-150px)] overflow-y-auto"> | |
| { | |
| articles.map((article) => ( | |
| <a | |
| href={`#art-${article.number}`} | |
| class="text-sm transition-colors duration-150 text-slate-700 hover:text-primary" | |
| x-on:click="$store.scrollSpy.activeId = $event.target.getAttribute('href').slice(1)" | |
| :class="text-primary font-semibold border-l-2 border-primary pl-2': $store.scrollSpy.activeId === 'art-' + article.number }" | |
| :aria-current="$store.scrollSpy.activeId === 'art-' + article.number ? 'true' : undefined" | |
| > | |
| Art.{article.number} {article.name.de} | |
| </a> | |
| )) | |
| } | |
| </nav> | |
| </aside> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment