ant-design/components/anchor/demo/targetOffset.md

43 lines
912 B
Markdown
Raw Normal View History

---
order: 5
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
import { Anchor } from 'antd';
2022-05-23 14:37:16 +08:00
import React, { useEffect, useState } from 'react';
const { Link } = Anchor;
const App: React.FC = () => {
2020-01-22 12:11:49 +08:00
const [targetOffset, setTargetOffset] = useState<number | undefined>(undefined);
2020-01-22 12:11:49 +08:00
useEffect(() => {
2020-01-21 16:21:37 +08:00
setTargetOffset(window.innerHeight / 2);
}, []);
2020-01-21 16:21:37 +08:00
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>
);
};
export default App;
```