Anchor
Hyperlinks zum Scrollen auf einer Seite.
Wann zu verwenden
- Zum Anzeigen von Anker-Hyperlinks auf der Seite und zum Springen zwischen ihnen.
Basic
Die einfachste Verwendung.
Example.astro
---
import Anchor from '@/components/navigation/Anchor.astro';
import AnchorLink from '@/components/navigation/AnchorLink.astro';
---
<Anchor container="window" offsetTop={100} bounds={50}>
<AnchorLink href="#basic-example" title="Basic demo" />
<AnchorLink href="#static-example" title="Static demo" />
<AnchorLink href="#api" title="API">
<AnchorLink href="#anchor-props" title="Anchor Props" />
<AnchorLink href="#anchorlink-props" title="AnchorLink Props" />
</AnchorLink>
</Anchor> Statischer Anker
Zustand nicht ändern, wenn die Seite scrollt.
Static.astro
---
import Anchor from '@/components/navigation/Anchor.astro';
import AnchorLink from '@/components/navigation/AnchorLink.astro';
---
<Anchor affix={false} container="window" offsetTop={100} bounds={50}>
<AnchorLink href="#basic-example" title="Basic demo" />
<AnchorLink href="#static-example" title="Static demo" />
<AnchorLink href="#api" title="API" />
</Anchor> Horizontaler Anker
Horizontal ausgerichtete Anker.
Horizontal.astro
---
import Anchor from '@/components/navigation/Anchor.astro';
import AnchorLink from '@/components/navigation/AnchorLink.astro';
---
<Anchor direction="horizontal" affix={false} container="window" offsetTop={100} bounds={50}>
<AnchorLink href="#basic-example" title="Basic demo" />
<AnchorLink href="#static-example" title="Static demo" />
<AnchorLink href="#api" title="API" />
</Anchor> API-Referenz
Anchor
| Eigenschaft | Beschreibung | Typ | Standard |
|---|---|---|---|
| affix | Fixed mode of Anchor | boolean | true |
| bounds | Bounding distance of anchor area, unit: px | number | 5 |
| offsetTop | Pixels to offset from top when calculating position of scroll | number | 0 |
| targetOffset | Anchor scroll offset, default as offsetTop | number | - |
| container | Scrolling container selector | string | 'window' |
| direction | Set Anchor direction | 'vertical' | 'horizontal' | 'vertical' |
AnchorLink
| Eigenschaft | Beschreibung | Typ | Standard |
|---|---|---|---|
| href | target of hyperlink | string | - |
| title | content of hyperlink | string | - |
| target | Specifies where to display the linked URL | string | - |