2016-05-05 16:52:36 +08:00
|
|
|
---
|
|
|
|
order: 7
|
2016-11-15 15:02:30 +08:00
|
|
|
title:
|
2016-08-11 11:41:06 +08:00
|
|
|
zh-CN: 自定义位置
|
|
|
|
en-US: To customize the position of modal
|
2016-05-05 16:52:36 +08:00
|
|
|
---
|
|
|
|
|
2016-08-11 11:41:06 +08:00
|
|
|
## zh-CN
|
|
|
|
|
2018-09-12 21:43:01 +08:00
|
|
|
使用 `centered` 或类似 `style.top` 的样式来设置对话框位置。
|
2016-05-05 16:52:36 +08:00
|
|
|
|
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
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
2022-05-23 14:37:16 +08:00
|
|
|
import { Button, Modal } from 'antd';
|
2022-05-19 09:46:26 +08:00
|
|
|
import React, { useState } from 'react';
|
2016-05-05 16:52:36 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => {
|
2022-08-23 16:55:57 +08:00
|
|
|
const [modal1Open, setModal1Open] = useState(false);
|
|
|
|
const [modal2Open, setModal2Open] = useState(false);
|
2022-05-18 19:29:01 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-08-23 16:55:57 +08:00
|
|
|
<Button type="primary" onClick={() => setModal1Open(true)}>
|
2022-05-18 19:29:01 +08:00
|
|
|
Display a modal dialog at 20px to Top
|
|
|
|
</Button>
|
|
|
|
<Modal
|
|
|
|
title="20px to Top"
|
|
|
|
style={{ top: 20 }}
|
2022-08-23 16:55:57 +08:00
|
|
|
visible={modal1Open}
|
|
|
|
onOk={() => setModal1Open(false)}
|
|
|
|
onCancel={() => setModal1Open(false)}
|
2022-05-18 19:29:01 +08:00
|
|
|
>
|
|
|
|
<p>some contents...</p>
|
|
|
|
<p>some contents...</p>
|
|
|
|
<p>some contents...</p>
|
|
|
|
</Modal>
|
|
|
|
<br />
|
|
|
|
<br />
|
2022-08-23 16:55:57 +08:00
|
|
|
<Button type="primary" onClick={() => setModal2Open(true)}>
|
2022-05-18 19:29:01 +08:00
|
|
|
Vertically centered modal dialog
|
|
|
|
</Button>
|
|
|
|
<Modal
|
|
|
|
title="Vertically centered modal dialog"
|
|
|
|
centered
|
2022-08-23 16:55:57 +08:00
|
|
|
visible={modal2Open}
|
|
|
|
onOk={() => setModal2Open(false)}
|
|
|
|
onCancel={() => setModal2Open(false)}
|
2022-05-18 19:29:01 +08:00
|
|
|
>
|
|
|
|
<p>some contents...</p>
|
|
|
|
<p>some contents...</p>
|
|
|
|
<p>some contents...</p>
|
|
|
|
</Modal>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2016-05-05 16:52:36 +08:00
|
|
|
|
2022-04-15 16:20:56 +08:00
|
|
|
export default App;
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|