mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-03 16:39:41 +08:00
9913f992b7
* chore: update for basic.md * chore: update for debug.md * chore: update for target.md * chore: import react * chore: update for debug.md with hooks * chore: refactor with typescript
1.0 KiB
1.0 KiB
order | title | ||||
---|---|---|---|---|---|
2 |
|
zh-CN
用 target
设置 Affix
需要监听其滚动事件的元素,默认为 window
。
en-US
Set a target
for 'Affix', which is listen to scroll event of target element (default is window
).
import React, { useState, FC } from 'react';
import { Affix, Button } from 'antd';
const Demo: FC = () => {
const [container, setContainer] = useState(null);
return (
<div className="scrollable-container" ref={setContainer}>
<div className="background">
<Affix target={() => container}>
<Button type="primary">Fixed at the top of container</Button>
</Affix>
</div>
</div>
)
};
ReactDOM.render(<Demo />, mountNode);