mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-12 07:09:55 +08:00
73 lines
1.7 KiB
Markdown
73 lines
1.7 KiB
Markdown
---
|
|
order: 7
|
|
title:
|
|
zh-CN: 自定义位置
|
|
en-US: To customize the position of modal
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
使用 `centered` 或类似 `style.top` 的样式来设置对话框位置。
|
|
|
|
## en-US
|
|
|
|
You can use `centered`,`style.top` or other styles to set position of modal dialog.
|
|
|
|
```jsx
|
|
import { Modal, Button } from 'antd';
|
|
|
|
class App extends React.Component {
|
|
state = {
|
|
modal1Visible: false,
|
|
modal2Visible: false,
|
|
};
|
|
|
|
setModal1Visible(modal1Visible) {
|
|
this.setState({ modal1Visible });
|
|
}
|
|
|
|
setModal2Visible(modal2Visible) {
|
|
this.setState({ modal2Visible });
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<>
|
|
<Button type="primary" onClick={() => this.setModal1Visible(true)}>
|
|
Display a modal dialog at 20px to Top
|
|
</Button>
|
|
<Modal
|
|
title="20px to Top"
|
|
style={{ top: 20 }}
|
|
visible={this.state.modal1Visible}
|
|
onOk={() => this.setModal1Visible(false)}
|
|
onCancel={() => this.setModal1Visible(false)}
|
|
>
|
|
<p>some contents...</p>
|
|
<p>some contents...</p>
|
|
<p>some contents...</p>
|
|
</Modal>
|
|
<br />
|
|
<br />
|
|
<Button type="primary" onClick={() => this.setModal2Visible(true)}>
|
|
Vertically centered modal dialog
|
|
</Button>
|
|
<Modal
|
|
title="Vertically centered modal dialog"
|
|
centered
|
|
visible={this.state.modal2Visible}
|
|
onOk={() => this.setModal2Visible(false)}
|
|
onCancel={() => this.setModal2Visible(false)}
|
|
>
|
|
<p>some contents...</p>
|
|
<p>some contents...</p>
|
|
<p>some contents...</p>
|
|
</Modal>
|
|
</>
|
|
);
|
|
}
|
|
}
|
|
|
|
ReactDOM.render(<App />, mountNode);
|
|
```
|