Back to Element Plus

Anchor

docs/en-US/component/anchor.md

2.13.73.7 KB
Original Source

Anchor

Through the anchor point, you can quickly find the position of the information content on the current page.

Basic Usage

The most basic usage

:::demo

anchor/basic

:::

Horizontal Mode

Horizontally aligned anchors

:::tip

Horizontal Mode does not support sub-link slots

:::

:::demo

anchor/horizontal

:::

Scroll Container

Custom scroll area, use offset props can set anchor scroll offset, listen the link-click event and prevents browser default behavior then it will not change history.

:::demo

anchor/scroll

:::

Listening for anchor link change

:::demo

anchor/change

:::

Underline type

set type="underline" change to underline type

:::demo

anchor/underline

:::

Affix Mode

Use the affix component to fix the anchor point within the page.

:::demo

anchor/affix

:::

Anchor API

Anchor Attributes

PropertyDescriptionTypeDefault
containerScroll container.string | HTMLElement | Window
offsetSet the offset of the anchor scroll.number0
boundThe offset of the element starting to trigger the anchor.number15
durationSet the scroll duration of the container, in milliseconds.number300
markerWhether to show the marker.^[boolean]true
typeSet Anchor type.^[enum]'default' | 'underline'default
directionSet Anchor direction.^[enum]'vertical' | 'horizontal'vertical
select-scroll-top ^(2.9.2)Scroll whether link is selected at the top^[boolean]false

Anchor Events

NameDescriptionType
changeCallback when the step changes^[Function](href: string) => void
clickTriggered when the user clicks on the link^[Function](e: MouseEvent, href?: string) => void

Anchor Exposes

NameDescriptionType
scrollToManually scroll to the specific position.^[Function](href: string) => void

Anchor Slots

NameDescription
defaultAnchorLink component list
PropertyDescriptionTypeDefault
titleThe text content of the anchor link.string
hrefThe address of the anchor link.string
NameDescription
defaultThe content of the anchor link.
sub-linkSlots for child links.