2016-08-18 11:27:37 +08:00
|
|
|
---
|
2016-10-30 15:11:22 +08:00
|
|
|
order: 2
|
2016-09-01 11:04:34 +08:00
|
|
|
title:
|
|
|
|
zh-CN: 滚动容器
|
|
|
|
en-US: Container to scroll.
|
2016-08-18 11:27:37 +08:00
|
|
|
---
|
|
|
|
|
2016-09-01 11:04:34 +08:00
|
|
|
## zh-CN
|
|
|
|
|
2016-08-18 11:27:37 +08:00
|
|
|
用 `target` 设置 `Affix` 需要监听其滚动事件的元素,默认为 `window`。
|
|
|
|
|
2016-09-01 11:04:34 +08:00
|
|
|
## en-US
|
|
|
|
|
2016-10-30 15:11:22 +08:00
|
|
|
Set a `target` for 'Affix', which is listen to scroll event of target element (default is `window`).
|
2016-09-01 11:04:34 +08:00
|
|
|
|
2016-08-18 11:27:37 +08:00
|
|
|
````jsx
|
|
|
|
import { Affix, Button } from 'antd';
|
|
|
|
|
|
|
|
const Demo = () => {
|
|
|
|
return (
|
2016-10-30 15:11:22 +08:00
|
|
|
<div className="view-port">
|
|
|
|
<div id="scrollable-container">
|
|
|
|
<div className="background">
|
2016-08-18 11:27:37 +08:00
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
<br />
|
2016-10-30 15:11:22 +08:00
|
|
|
<Affix target={() => document.getElementById('scrollable-container')} offsetTop={20}>
|
2016-09-01 11:04:34 +08:00
|
|
|
<Button type="primary">Fixed at the top of container</Button>
|
2016-08-18 11:27:37 +08:00
|
|
|
</Affix>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
ReactDOM.render(<Demo />, mountNode);
|
|
|
|
````
|
2016-10-30 15:11:22 +08:00
|
|
|
|
|
|
|
<style>
|
|
|
|
#components-affix-demo-target .view-port {
|
|
|
|
height: 100px;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
#components-affix-demo-target #scrollable-container {
|
|
|
|
height: 100%;
|
|
|
|
overflow-y: scroll;
|
|
|
|
}
|
|
|
|
#components-affix-demo-target .background {
|
|
|
|
height: 300px;
|
|
|
|
background-image: url('https://zos.alipayobjects.com/rmsportal/RmjwQiJorKyobvI.jpg');
|
|
|
|
}
|
|
|
|
</style>
|