2019-07-24 13:43:02 +08:00
|
|
|
---
|
2019-09-06 19:54:13 +08:00
|
|
|
order: 5
|
2019-07-24 13:43:02 +08:00
|
|
|
title:
|
|
|
|
zh-CN: 设置锚点滚动偏移量
|
|
|
|
en-US: Set Anchor scroll offset
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
锚点目标滚动到屏幕正中间。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
Anchor target scroll to screen center.
|
|
|
|
|
2020-01-21 16:21:37 +08:00
|
|
|
```tsx
|
2020-01-22 12:11:49 +08:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2019-07-24 13:43:02 +08:00
|
|
|
import { Anchor } from 'antd';
|
|
|
|
|
|
|
|
const { Link } = Anchor;
|
|
|
|
|
2020-01-21 17:14:58 +08:00
|
|
|
const AnchorExample: React.FC = () => {
|
2020-01-22 12:11:49 +08:00
|
|
|
const [targetOffset, setTargetOffset] = useState<number | undefined>(undefined);
|
|
|
|
useEffect(() => {
|
2020-01-21 16:21:37 +08:00
|
|
|
setTargetOffset(window.innerHeight / 2);
|
|
|
|
}, []);
|
|
|
|
return (
|
|
|
|
<Anchor targetOffset={targetOffset}>
|
|
|
|
<Link href="#components-anchor-demo-basic" title="Basic demo" />
|
|
|
|
<Link href="#components-anchor-demo-static" title="Static demo" />
|
|
|
|
<Link href="#API" title="API">
|
|
|
|
<Link href="#Anchor-Props" title="Anchor Props" />
|
|
|
|
<Link href="#Link-Props" title="Link Props" />
|
|
|
|
</Link>
|
|
|
|
</Anchor>
|
|
|
|
);
|
|
|
|
};
|
2019-07-24 14:07:43 +08:00
|
|
|
|
|
|
|
ReactDOM.render(<AnchorExample />, mountNode);
|
2019-07-24 13:43:02 +08:00
|
|
|
```
|