ant-design/components/modal/demo/position.md

73 lines
1.7 KiB
Markdown
Raw Normal View History

---
order: 7
title:
2016-08-11 11:41:06 +08:00
zh-CN: 自定义位置
en-US: To customize the position of modal
---
2016-08-11 11:41:06 +08:00
## zh-CN
2018-09-12 21:43:01 +08:00
使用 `centered` 或类似 `style.top` 的样式来设置对话框位置。
2016-08-11 11:41:06 +08:00
## en-US
2019-05-07 14:57:32 +08:00
You can use `centered`,`style.top` or other styles to set position of modal dialog.
2016-08-11 11:41:06 +08:00
2019-05-07 14:57:32 +08:00
```jsx
import { Modal, Button } from 'antd';
class App extends React.Component {
state = {
modal1Visible: false,
modal2Visible: false,
2019-05-07 14:57:32 +08:00
};
2018-06-27 15:55:04 +08:00
2016-05-09 16:45:58 +08:00
setModal1Visible(modal1Visible) {
this.setState({ modal1Visible });
}
2018-06-27 15:55:04 +08:00
2016-05-09 16:45:58 +08:00
setModal2Visible(modal2Visible) {
this.setState({ modal2Visible });
}
2018-06-27 15:55:04 +08:00
render() {
return (
2020-07-16 13:46:57 +08:00
<>
2019-05-07 14:57:32 +08:00
<Button type="primary" onClick={() => this.setModal1Visible(true)}>
Display a modal dialog at 20px to Top
</Button>
2016-05-09 16:45:58 +08:00
<Modal
2016-08-11 11:41:06 +08:00
title="20px to Top"
2016-05-09 16:45:58 +08:00
style={{ top: 20 }}
visible={this.state.modal1Visible}
onOk={() => this.setModal1Visible(false)}
onCancel={() => this.setModal1Visible(false)}
>
2016-08-11 11:41:06 +08:00
<p>some contents...</p>
<p>some contents...</p>
<p>some contents...</p>
2016-05-09 16:45:58 +08:00
</Modal>
2019-05-07 14:57:32 +08:00
<br />
<br />
<Button type="primary" onClick={() => this.setModal2Visible(true)}>
Vertically centered modal dialog
</Button>
<Modal
2016-08-11 11:41:06 +08:00
title="Vertically centered modal dialog"
2018-07-31 17:05:07 +08:00
centered
2016-05-09 16:45:58 +08:00
visible={this.state.modal2Visible}
onOk={() => this.setModal2Visible(false)}
onCancel={() => this.setModal2Visible(false)}
>
2016-08-11 11:41:06 +08:00
<p>some contents...</p>
<p>some contents...</p>
<p>some contents...</p>
</Modal>
2020-07-16 13:46:57 +08:00
</>
);
}
}
export default () => <App />;
2019-05-07 14:57:32 +08:00
```