Skip to content

Commit ad15348

Browse files
committed
feat: 支持 Selector 参数
1 parent 0998703 commit ad15348

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed
Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
export function update(id, options) {
22
const mask = document.getElementById(id);
33
if (mask) {
4-
const { show, containerId } = options;
4+
const { show } = options;
55
const el = document.querySelector(`[data-bb-mask="${id}"]`);
6-
if (containerId) {
7-
const container = document.getElementById(containerId);
8-
if (container) {
9-
const position = container.style.getPropertyValue('position');
10-
if (position === '' || position === 'static') {
11-
container.style.setProperty('position', 'relative');
12-
}
13-
14-
if (show) {
15-
el.style.setProperty('--bb-mask-position', 'absolute');
16-
container.appendChild(el);
17-
}
6+
const container = getContainerBySelector(options);
7+
if (container) {
8+
const position = container.style.getPropertyValue('position');
9+
if (position === '' || position === 'static') {
10+
container.style.setProperty('position', 'relative');
11+
}
12+
if (show) {
13+
el.style.setProperty('--bb-mask-position', 'absolute');
14+
container.appendChild(el);
1815
}
1916
}
2017
else {
@@ -31,3 +28,10 @@
3128
}
3229
}
3330
}
31+
32+
const getContainerBySelector = options => {
33+
const selector = getContainerById(options.containerId) ?? options.selector;
34+
return selector ? document.querySelector(selector) : null;
35+
}
36+
37+
const getContainerById = id => id ? `#${id}` : null;

0 commit comments

Comments
 (0)