Anchor
한 페이지에서 스크롤하기 위한 하이퍼링크입니다.
언제 사용하나요
- 페이지에 앵커 하이퍼링크를 표시하고 그 사이를 이동하기 위해.
기본
가장 간단한 사용법.
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.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.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 참조
Anchor
| 속성 | 설명 | 타입 | 기본값 |
|---|---|---|---|
| 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
| 속성 | 설명 | 타입 | 기본값 |
|---|---|---|---|
| href | target of hyperlink | string | - |
| title | content of hyperlink | string | - |
| target | Specifies where to display the linked URL | string | - |