Anchor
Hyperlinks to scroll on one page.
When To Use
- For displaying anchor hyperlinks on page and jumping between them.
Basic
The simplest usage.
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> Static Anchor
Do not change state when page is scrolling.
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> Horizontal Anchor
Horizontally aligned anchors.
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 Reference
Anchor
| Property | Description | Type | Default |
|---|---|---|---|
| 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
| Property | Description | Type | Default |
|---|---|---|---|
| href | target of hyperlink | string | - |
| title | content of hyperlink | string | - |
| target | Specifies where to display the linked URL | string | - |