Skip to content

Commit 229fd8e

Browse files
committed
refactor: 移动可拖动垂直计算逻辑到 Dialog 脚本内
1 parent f477aa4 commit 229fd8e

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/BootstrapBlazor/Components/Modal/Modal.razor.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,6 @@ export function init(id, invoke, shownCallback, closeCallback) {
1717
Data.set(id, modal)
1818

1919
EventHandler.on(el, 'shown.bs.modal', () => {
20-
const dialog = el.querySelector('.modal-dialog');
21-
if (dialog.classList.contains('is-draggable-center')) {
22-
const width = dialog.offsetWidth / 2;
23-
const height = dialog.offsetHeight / 2;
24-
25-
dialog.style.setProperty("margin-left", `calc(50vw - ${width}px)`);
26-
dialog.style.setProperty("margin-top", `calc(50vh - ${height}px)`);
27-
dialog.classList.remove('is-draggable-center');
28-
}
29-
3020
invoke.invokeMethodAsync(shownCallback)
3121
})
3222
EventHandler.on(el, 'hidden.bs.modal', e => {

src/BootstrapBlazor/Components/Modal/ModalDialog.razor.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ export function init(id) {
119119
}
120120
)
121121
}
122+
123+
if (el.classList.contains('is-draggable-center')) {
124+
const width = el.offsetWidth / 2;
125+
const height = el.offsetHeight / 2;
126+
127+
el.style.setProperty("margin-left", `calc(50vw - ${width}px)`);
128+
el.style.setProperty("margin-top", `calc(50vh - ${height}px)`);
129+
el.classList.remove('is-draggable-center');
130+
}
122131
}
123132

124133
export function dispose(id) {

0 commit comments

Comments
 (0)