2016-10-28 14:02:55 +08:00
|
|
|
|
---
|
|
|
|
|
category: Components
|
|
|
|
|
title: Anchor
|
2022-11-17 18:28:13 +08:00
|
|
|
|
subtitle: 锚点
|
2022-11-30 20:14:41 +08:00
|
|
|
|
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*TBTSR4PyVmkAAAAAAAAAAAAADrJ8AQ/original
|
2022-11-09 12:28:04 +08:00
|
|
|
|
demo:
|
|
|
|
|
cols: 2
|
2022-11-17 16:49:09 +08:00
|
|
|
|
group:
|
|
|
|
|
title: 导航
|
|
|
|
|
order: 3
|
2016-10-28 14:02:55 +08:00
|
|
|
|
---
|
|
|
|
|
|
2016-11-09 14:22:38 +08:00
|
|
|
|
用于跳转到页面指定位置。
|
2016-10-28 14:02:55 +08:00
|
|
|
|
|
|
|
|
|
## 何时使用
|
|
|
|
|
|
2016-11-03 16:45:13 +08:00
|
|
|
|
需要展现当前页面上可供跳转的锚点链接,以及快速在锚点之间跳转。
|
2016-10-28 14:02:55 +08:00
|
|
|
|
|
2022-10-31 14:49:43 +08:00
|
|
|
|
> 开发者注意事项:
|
|
|
|
|
>
|
|
|
|
|
> 自 `4.24.0` 起,由于组件从 class 重构成 FC,之前一些获取 `ref` 并调用内部实例方法的写法都会失效
|
|
|
|
|
|
2022-11-09 12:28:04 +08:00
|
|
|
|
## 代码演示
|
|
|
|
|
|
2022-11-17 17:31:26 +08:00
|
|
|
|
<!-- prettier-ignore -->
|
2022-12-12 19:44:32 +08:00
|
|
|
|
<code src="./demo/basic.tsx" iframe="200">基本</code>
|
2022-11-09 12:28:04 +08:00
|
|
|
|
<code src="./demo/static.tsx">静态位置</code>
|
|
|
|
|
<code src="./demo/onClick.tsx">自定义 onClick 事件</code>
|
|
|
|
|
<code src="./demo/customizeHighlight.tsx">自定义锚点高亮</code>
|
2022-12-12 19:44:32 +08:00
|
|
|
|
<code src="./demo/targetOffset.tsx" iframe="200">设置锚点滚动偏移量</code>
|
2022-11-09 12:28:04 +08:00
|
|
|
|
<code src="./demo/onChange.tsx">监听锚点链接改变</code>
|
2022-11-30 15:55:43 +08:00
|
|
|
|
<code src="./demo/legacy-anchor.tsx" debug>废弃的 JSX 示例</code>
|
2022-11-09 12:28:04 +08:00
|
|
|
|
|
2016-10-28 14:02:55 +08:00
|
|
|
|
## API
|
|
|
|
|
|
2016-11-03 16:45:13 +08:00
|
|
|
|
### Anchor Props
|
|
|
|
|
|
2022-11-17 17:31:26 +08:00
|
|
|
|
| 成员 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
|
| affix | 固定模式 | boolean | true | |
|
|
|
|
|
| bounds | 锚点区域边界 | number | 5 | |
|
|
|
|
|
| getContainer | 指定滚动的容器 | () => HTMLElement | () => window | |
|
|
|
|
|
| getCurrentAnchor | 自定义高亮的锚点 | (activeLink: string) => string | - | |
|
|
|
|
|
| offsetTop | 距离窗口顶部达到指定偏移量后触发 | number | | |
|
2022-12-13 22:18:43 +08:00
|
|
|
|
| showInkInFixed | `affix={false}` 时是否显示小方块 | boolean | false | |
|
2022-11-17 17:31:26 +08:00
|
|
|
|
| targetOffset | 锚点滚动偏移量,默认与 offsetTop 相同,[例子](#components-anchor-demo-targetOffset) | number | - | |
|
|
|
|
|
| onChange | 监听锚点链接改变 | (currentActiveLink: string) => void | - | |
|
2022-12-06 18:18:38 +08:00
|
|
|
|
| onClick | `click` 事件的 handler | (e: MouseEvent, link: object) => void | - | |
|
2022-11-30 15:55:43 +08:00
|
|
|
|
| items | 数据化配置选项内容,支持通过 children 嵌套 | { href, title, target, children }\[] | - | |
|
2016-11-07 11:04:36 +08:00
|
|
|
|
|
|
|
|
|
### Link Props
|
2016-10-28 14:02:55 +08:00
|
|
|
|
|
2022-03-31 11:17:17 +08:00
|
|
|
|
| 成员 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| ------ | -------------------------------- | --------- | ------ | ---- |
|
|
|
|
|
| href | 锚点链接 | string | - | |
|
|
|
|
|
| target | 该属性指定在何处显示链接的资源。 | string | - | |
|
|
|
|
|
| title | 文字内容 | ReactNode | - | |
|