@whitesev/domutils 1.0.0 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,46 @@
1
+ ## 使用js重新对jQuery的部分函数进行了仿写
2
+
3
+ * addClass `给元素添加class`
4
+ * after `在元素后面添加兄弟元素或HTML字符串`
5
+ * animate `在一定时间内改变元素的样式属性,实现动画效果`
6
+ * append `函数在元素内部末尾添加子元素或HTML字符串`
7
+ * attr `获取或设置元素的属性值`
8
+ * before `在元素前面添加兄弟元素或HTML字符串`
9
+ * blur `绑定或触发元素的blur事件`
10
+ * click `绑定或触发元素的click事件`
11
+ * css `获取或设置元素的样式属性值`
12
+ * delegate `为指定元素的子元素绑定事件`
13
+ * empty `移除元素的所有子元素`
14
+ * fadeIn `淡入元素`
15
+ * fadeOut `淡出元素`
16
+ * focus `绑定或触发元素的focus事件`
17
+ * height `获取元素的高度`
18
+ * hide `隐藏元素`
19
+ * hover `当鼠标移入或移出元素时触发事件`
20
+ * html `获取或设置元素的HTML内容`
21
+ * keydown `当按键按下时触发事件`
22
+ * keyup `当按键松开时触发事件`
23
+ * next `获取当前元素的后一个兄弟元素`
24
+ * off `取消绑定事件`
25
+ * offset `设置或返回被选元素相对于文档的偏移坐标`
26
+ * on `绑定事件`
27
+ * outerHeight `获取元素的外部高度(包括边框和外边距)`
28
+ * outerWidth `获取元素的外部宽度(包括边框和外边距)`
29
+ * parent `获取当前元素的父元素`
30
+ * prepend `函数 在元素内部开头添加子元素或HTML字符串`
31
+ * prev `获取当前元素的前一个兄弟元素`
32
+ * prop `获取或设置元素的属性值`
33
+ * ready `等待文档加载完成后执行指定的函数`
34
+ * remove `移除元素`
35
+ * removeAttr `移除元素的属性`
36
+ * removeProp `移除元素的属性`
37
+ * show `显示元素`
38
+ * siblings `获取当前元素的所有兄弟元素`
39
+ * text `获取或设置元素的文本内容`
40
+ * toggle `切换元素的显示和隐藏状态`
41
+ * trigger `主动触发事件`
42
+ * val `获取或设置元素的value属性值`
43
+ * width `获取元素的宽度`
44
+ * wrap `将一个元素包裹在指定的HTML元素中`
45
+
46
+ 具体注释在代码中查看
package/dist/index.cjs.js CHANGED
@@ -1,5 +1,38 @@
1
1
  'use strict';
2
2
 
3
+ const DOMUtilsCoreDefaultEnv = {
4
+ document: document,
5
+ window: window,
6
+ globalThis: globalThis,
7
+ self: self,
8
+ };
9
+ const DOMUtilsCoreEnv = {
10
+ document: document,
11
+ window: window,
12
+ globalThis: globalThis,
13
+ self: self,
14
+ };
15
+ const DOMUtilsCore = {
16
+ init(option) {
17
+ if (!option) {
18
+ option = Object.assign({}, DOMUtilsCoreDefaultEnv);
19
+ }
20
+ Object.assign(DOMUtilsCoreEnv, option);
21
+ },
22
+ get document() {
23
+ return DOMUtilsCoreEnv.document;
24
+ },
25
+ get window() {
26
+ return DOMUtilsCoreEnv.window;
27
+ },
28
+ get globalThis() {
29
+ return DOMUtilsCoreEnv.globalThis;
30
+ },
31
+ get self() {
32
+ return DOMUtilsCoreEnv.self;
33
+ },
34
+ };
35
+
3
36
  /** 通用工具类 */
4
37
  const CommonDOMUtils = {
5
38
  /**
@@ -16,7 +49,7 @@ const CommonDOMUtils = {
16
49
  showElement(element) {
17
50
  let dupNode = element.cloneNode(true);
18
51
  dupNode.setAttribute("style", "visibility: hidden !important;display:block !important;");
19
- document.documentElement.appendChild(dupNode);
52
+ DOMUtilsCore.document.documentElement.appendChild(dupNode);
20
53
  return {
21
54
  /**
22
55
  * 恢复修改的style
@@ -109,11 +142,14 @@ const OriginPrototype = {
109
142
  };
110
143
 
111
144
  class DOMUtils {
145
+ constructor(option) {
146
+ DOMUtilsCore.init(option);
147
+ }
112
148
  /** 版本号 */
113
149
  version = "2024.5.24";
114
150
  attr(element, attrName, attrValue) {
115
151
  if (typeof element === "string") {
116
- element = document.querySelector(element);
152
+ element = DOMUtilsCore.document.querySelector(element);
117
153
  }
118
154
  if (element == null) {
119
155
  return;
@@ -150,7 +186,7 @@ class DOMUtils {
150
186
  property,
151
187
  /** 自定义属性 */
152
188
  attributes) {
153
- let tempElement = document.createElement(tagName);
189
+ let tempElement = DOMUtilsCore.document.createElement(tagName);
154
190
  if (typeof property === "string") {
155
191
  tempElement.innerHTML = property;
156
192
  return tempElement;
@@ -204,7 +240,7 @@ class DOMUtils {
204
240
  return propertyValue;
205
241
  }
206
242
  if (typeof element === "string") {
207
- element = document.querySelector(element);
243
+ element = DOMUtilsCore.document.querySelector(element);
208
244
  }
209
245
  if (element == null) {
210
246
  return;
@@ -238,7 +274,7 @@ class DOMUtils {
238
274
  }
239
275
  text(element, text) {
240
276
  if (typeof element === "string") {
241
- element = document.querySelector(element);
277
+ element = DOMUtilsCore.document.querySelector(element);
242
278
  }
243
279
  if (element == null) {
244
280
  return;
@@ -260,7 +296,7 @@ class DOMUtils {
260
296
  }
261
297
  html(element, html) {
262
298
  if (typeof element === "string") {
263
- element = document.querySelector(element);
299
+ element = DOMUtilsCore.document.querySelector(element);
264
300
  }
265
301
  if (element == null) {
266
302
  return;
@@ -294,7 +330,7 @@ class DOMUtils {
294
330
  click(element, handler, details, useDispatchToTriggerEvent) {
295
331
  let DOMUtilsContext = this;
296
332
  if (typeof element === "string") {
297
- element = document.querySelector(element);
333
+ element = DOMUtilsCore.document.querySelector(element);
298
334
  }
299
335
  if (element == null) {
300
336
  return;
@@ -323,7 +359,7 @@ class DOMUtils {
323
359
  blur(element, handler, details, useDispatchToTriggerEvent) {
324
360
  let DOMUtilsContext = this;
325
361
  if (typeof element === "string") {
326
- element = document.querySelector(element);
362
+ element = DOMUtilsCore.document.querySelector(element);
327
363
  }
328
364
  if (element == null) {
329
365
  return;
@@ -352,7 +388,7 @@ class DOMUtils {
352
388
  focus(element, handler, details, useDispatchToTriggerEvent) {
353
389
  let DOMUtilsContext = this;
354
390
  if (typeof element === "string") {
355
- element = document.querySelector(element);
391
+ element = DOMUtilsCore.document.querySelector(element);
356
392
  }
357
393
  if (element == null) {
358
394
  return;
@@ -401,7 +437,7 @@ class DOMUtils {
401
437
  }
402
438
  val(element, value) {
403
439
  if (typeof element === "string") {
404
- element = document.querySelector(element);
440
+ element = DOMUtilsCore.document.querySelector(element);
405
441
  }
406
442
  if (element == null) {
407
443
  return;
@@ -430,7 +466,7 @@ class DOMUtils {
430
466
  return;
431
467
  }
432
468
  if (typeof element === "string") {
433
- element = document.querySelector(element);
469
+ element = DOMUtilsCore.document.querySelector(element);
434
470
  }
435
471
  if (propValue == null) {
436
472
  return element[propName];
@@ -450,7 +486,7 @@ class DOMUtils {
450
486
  * */
451
487
  removeAttr(element, attrName) {
452
488
  if (typeof element === "string") {
453
- element = document.querySelector(element);
489
+ element = DOMUtilsCore.document.querySelector(element);
454
490
  }
455
491
  if (element == null) {
456
492
  return;
@@ -468,7 +504,7 @@ class DOMUtils {
468
504
  */
469
505
  removeClass(element, className) {
470
506
  if (typeof element === "string") {
471
- element = document.querySelector(element);
507
+ element = DOMUtilsCore.document.querySelector(element);
472
508
  }
473
509
  if (element == null) {
474
510
  return;
@@ -489,7 +525,7 @@ class DOMUtils {
489
525
  * */
490
526
  removeProp(element, propName) {
491
527
  if (typeof element === "string") {
492
- element = document.querySelector(element);
528
+ element = DOMUtilsCore.document.querySelector(element);
493
529
  }
494
530
  if (element == null) {
495
531
  return;
@@ -508,7 +544,7 @@ class DOMUtils {
508
544
  replaceWith(element, newElement) {
509
545
  let DOMUtilsContext = this;
510
546
  if (typeof element === "string") {
511
- element = document.querySelector(element);
547
+ element = DOMUtilsCore.document.querySelector(element);
512
548
  }
513
549
  if (element == null) {
514
550
  return;
@@ -536,7 +572,7 @@ class DOMUtils {
536
572
  * */
537
573
  addClass(element, className) {
538
574
  if (typeof element === "string") {
539
- element = document.querySelector(element);
575
+ element = DOMUtilsCore.document.querySelector(element);
540
576
  }
541
577
  if (element == null) {
542
578
  return;
@@ -554,7 +590,7 @@ class DOMUtils {
554
590
  * */
555
591
  append(element, content) {
556
592
  if (typeof element === "string") {
557
- element = document.querySelector(element);
593
+ element = DOMUtilsCore.document.querySelector(element);
558
594
  }
559
595
  if (element == null) {
560
596
  return;
@@ -577,7 +613,7 @@ class DOMUtils {
577
613
  * */
578
614
  prepend(element, content) {
579
615
  if (typeof element === "string") {
580
- element = document.querySelector(element);
616
+ element = DOMUtilsCore.document.querySelector(element);
581
617
  }
582
618
  if (element == null) {
583
619
  return;
@@ -600,7 +636,7 @@ class DOMUtils {
600
636
  * */
601
637
  after(element, content) {
602
638
  if (typeof element === "string") {
603
- element = document.querySelector(element);
639
+ element = DOMUtilsCore.document.querySelector(element);
604
640
  }
605
641
  if (element == null) {
606
642
  return;
@@ -623,7 +659,7 @@ class DOMUtils {
623
659
  * */
624
660
  before(element, content) {
625
661
  if (typeof element === "string") {
626
- element = document.querySelector(element);
662
+ element = DOMUtilsCore.document.querySelector(element);
627
663
  }
628
664
  if (element == null) {
629
665
  return;
@@ -647,7 +683,7 @@ class DOMUtils {
647
683
  remove(target) {
648
684
  let DOMUtilsContext = this;
649
685
  if (typeof target === "string") {
650
- target = document.querySelectorAll(target);
686
+ target = DOMUtilsCore.document.querySelectorAll(target);
651
687
  }
652
688
  if (target == null) {
653
689
  return;
@@ -672,7 +708,7 @@ class DOMUtils {
672
708
  * */
673
709
  empty(element) {
674
710
  if (typeof element === "string") {
675
- element = document.querySelector(element);
711
+ element = DOMUtilsCore.document.querySelector(element);
676
712
  }
677
713
  if (element == null) {
678
714
  return;
@@ -709,7 +745,7 @@ class DOMUtils {
709
745
  let DOMUtilsContext = this;
710
746
  let args = arguments;
711
747
  if (typeof element === "string") {
712
- element = document.querySelectorAll(element);
748
+ element = DOMUtilsCore.document.querySelectorAll(element);
713
749
  }
714
750
  if (element == null) {
715
751
  return;
@@ -760,7 +796,7 @@ class DOMUtils {
760
796
  if (_selector_) {
761
797
  /* 存在自定义子元素选择器 */
762
798
  let totalParent = CommonDOMUtils.isWin(elementItem)
763
- ? document.documentElement
799
+ ? DOMUtilsCore.document.documentElement
764
800
  : elementItem;
765
801
  if (target.matches(_selector_)) {
766
802
  /* 当前目标可以被selector所匹配到 */
@@ -826,7 +862,7 @@ class DOMUtils {
826
862
  }
827
863
  let args = arguments;
828
864
  if (typeof element === "string") {
829
- element = document.querySelectorAll(element);
865
+ element = DOMUtilsCore.document.querySelectorAll(element);
830
866
  }
831
867
  if (element == null) {
832
868
  return;
@@ -910,7 +946,7 @@ class DOMUtils {
910
946
  */
911
947
  offAll(element, eventType) {
912
948
  if (typeof element === "string") {
913
- element = document.querySelectorAll(element);
949
+ element = DOMUtilsCore.document.querySelectorAll(element);
914
950
  }
915
951
  if (element == null) {
916
952
  return;
@@ -970,7 +1006,7 @@ class DOMUtils {
970
1006
  */
971
1007
  trigger(element, eventType, details, useDispatchToTriggerEvent = true) {
972
1008
  if (typeof element === "string") {
973
- element = document.querySelector(element);
1009
+ element = DOMUtilsCore.document.querySelector(element);
974
1010
  }
975
1011
  if (element == null) {
976
1012
  return;
@@ -1028,7 +1064,7 @@ class DOMUtils {
1028
1064
  */
1029
1065
  offset(element) {
1030
1066
  if (typeof element === "string") {
1031
- element = document.querySelector(element);
1067
+ element = DOMUtilsCore.document.querySelector(element);
1032
1068
  }
1033
1069
  if (element == null) {
1034
1070
  return;
@@ -1036,21 +1072,21 @@ class DOMUtils {
1036
1072
  let rect = element.getBoundingClientRect();
1037
1073
  return {
1038
1074
  /** y轴偏移 */
1039
- top: rect.top + globalThis.scrollY,
1075
+ top: rect.top + DOMUtilsCore.globalThis.scrollY,
1040
1076
  /** x轴偏移 */
1041
- left: rect.left + globalThis.scrollX,
1077
+ left: rect.left + DOMUtilsCore.globalThis.scrollX,
1042
1078
  };
1043
1079
  }
1044
1080
  width(element, isShow = false) {
1045
1081
  let DOMUtilsContext = this;
1046
1082
  if (typeof element === "string") {
1047
- element = document.querySelector(element);
1083
+ element = DOMUtilsCore.document.querySelector(element);
1048
1084
  }
1049
1085
  if (element == null) {
1050
1086
  return;
1051
1087
  }
1052
1088
  if (CommonDOMUtils.isWin(element)) {
1053
- return window.document.documentElement.clientWidth;
1089
+ return DOMUtilsCore.window.document.documentElement.clientWidth;
1054
1090
  }
1055
1091
  if (element.nodeType === 9) {
1056
1092
  /* Document文档节点 */
@@ -1093,10 +1129,10 @@ class DOMUtils {
1093
1129
  height(element, isShow = false) {
1094
1130
  let DOMUtilsContext = this;
1095
1131
  if (CommonDOMUtils.isWin(element)) {
1096
- return window.document.documentElement.clientHeight;
1132
+ return DOMUtilsCore.window.document.documentElement.clientHeight;
1097
1133
  }
1098
1134
  if (typeof element === "string") {
1099
- element = document.querySelector(element);
1135
+ element = DOMUtilsCore.document.querySelector(element);
1100
1136
  }
1101
1137
  if (element == null) {
1102
1138
  // @ts-ignore
@@ -1143,10 +1179,10 @@ class DOMUtils {
1143
1179
  outerWidth(element, isShow = false) {
1144
1180
  let DOMUtilsContext = this;
1145
1181
  if (CommonDOMUtils.isWin(element)) {
1146
- return window.innerWidth;
1182
+ return DOMUtilsCore.window.innerWidth;
1147
1183
  }
1148
1184
  if (typeof element === "string") {
1149
- element = document.querySelector(element);
1185
+ element = DOMUtilsCore.document.querySelector(element);
1150
1186
  }
1151
1187
  if (element == null) {
1152
1188
  // @ts-ignore
@@ -1169,10 +1205,10 @@ class DOMUtils {
1169
1205
  outerHeight(element, isShow = false) {
1170
1206
  let DOMUtilsContext = this;
1171
1207
  if (CommonDOMUtils.isWin(element)) {
1172
- return window.innerHeight;
1208
+ return DOMUtilsCore.window.innerHeight;
1173
1209
  }
1174
1210
  if (typeof element === "string") {
1175
- element = document.querySelector(element);
1211
+ element = DOMUtilsCore.document.querySelector(element);
1176
1212
  }
1177
1213
  if (element == null) {
1178
1214
  // @ts-ignore
@@ -1233,7 +1269,7 @@ class DOMUtils {
1233
1269
  */
1234
1270
  animate(element, styles, duration = 1000, callback = null) {
1235
1271
  if (typeof element === "string") {
1236
- element = document.querySelector(element);
1272
+ element = DOMUtilsCore.document.querySelector(element);
1237
1273
  }
1238
1274
  if (element == null) {
1239
1275
  return;
@@ -1285,14 +1321,14 @@ class DOMUtils {
1285
1321
  */
1286
1322
  wrap(element, wrapperHTML) {
1287
1323
  if (typeof element === "string") {
1288
- element = document.querySelector(element);
1324
+ element = DOMUtilsCore.document.querySelector(element);
1289
1325
  }
1290
1326
  if (element == null) {
1291
1327
  return;
1292
1328
  }
1293
1329
  element = element;
1294
1330
  // 创建一个新的div元素,并将wrapperHTML作为其innerHTML
1295
- let wrapper = document.createElement("div");
1331
+ let wrapper = DOMUtilsCore.document.createElement("div");
1296
1332
  wrapper.innerHTML = wrapperHTML;
1297
1333
  let wrapperFirstChild = wrapper.firstChild;
1298
1334
  // 将要包裹的元素插入目标元素前面
@@ -1302,7 +1338,7 @@ class DOMUtils {
1302
1338
  }
1303
1339
  prev(element) {
1304
1340
  if (typeof element === "string") {
1305
- element = document.querySelector(element);
1341
+ element = DOMUtilsCore.document.querySelector(element);
1306
1342
  }
1307
1343
  if (element == null) {
1308
1344
  return;
@@ -1311,7 +1347,7 @@ class DOMUtils {
1311
1347
  }
1312
1348
  next(element) {
1313
1349
  if (typeof element === "string") {
1314
- element = document.querySelector(element);
1350
+ element = DOMUtilsCore.document.querySelector(element);
1315
1351
  }
1316
1352
  if (element == null) {
1317
1353
  return;
@@ -1324,15 +1360,15 @@ class DOMUtils {
1324
1360
  * let DOMUtils = window.DOMUtils.noConflict()
1325
1361
  */
1326
1362
  noConflict() {
1327
- if (window.DOMUtils) {
1363
+ if (DOMUtilsCore.window.DOMUtils) {
1328
1364
  CommonDOMUtils.delete(window, "DOMUtils");
1329
1365
  }
1330
- window.DOMUtils = this;
1366
+ DOMUtilsCore.window.DOMUtils = this;
1331
1367
  return this;
1332
1368
  }
1333
1369
  siblings(element) {
1334
1370
  if (typeof element === "string") {
1335
- element = document.querySelector(element);
1371
+ element = DOMUtilsCore.document.querySelector(element);
1336
1372
  }
1337
1373
  if (element == null) {
1338
1374
  return;
@@ -1353,7 +1389,7 @@ class DOMUtils {
1353
1389
  parent(element) {
1354
1390
  let DOMUtilsContext = this;
1355
1391
  if (typeof element === "string") {
1356
- element = document.querySelector(element);
1392
+ element = DOMUtilsCore.document.querySelector(element);
1357
1393
  }
1358
1394
  if (element == null) {
1359
1395
  return;
@@ -1381,7 +1417,7 @@ class DOMUtils {
1381
1417
  }
1382
1418
  }
1383
1419
  function parseHTMLByCreateDom() {
1384
- let tempDIV = document.createElement("div");
1420
+ let tempDIV = DOMUtilsCore.document.createElement("div");
1385
1421
  tempDIV.innerHTML = html;
1386
1422
  if (isComplete) {
1387
1423
  return tempDIV;
@@ -1414,7 +1450,7 @@ class DOMUtils {
1414
1450
  hover(element, handler, option) {
1415
1451
  let DOMUtilsContext = this;
1416
1452
  if (typeof element === "string") {
1417
- element = document.querySelector(element);
1453
+ element = DOMUtilsCore.document.querySelector(element);
1418
1454
  }
1419
1455
  if (element == null) {
1420
1456
  return;
@@ -1437,7 +1473,7 @@ class DOMUtils {
1437
1473
  return;
1438
1474
  }
1439
1475
  if (typeof target === "string") {
1440
- target = document.querySelectorAll(target);
1476
+ target = DOMUtilsCore.document.querySelectorAll(target);
1441
1477
  }
1442
1478
  if (target instanceof NodeList || target instanceof Array) {
1443
1479
  target = target;
@@ -1446,6 +1482,7 @@ class DOMUtils {
1446
1482
  }
1447
1483
  }
1448
1484
  else {
1485
+ target = target;
1449
1486
  target.style.display = "";
1450
1487
  if (!CommonDOMUtils.isShow(target)) {
1451
1488
  /* 仍然是不显示,尝试使用强覆盖 */
@@ -1468,7 +1505,7 @@ class DOMUtils {
1468
1505
  return;
1469
1506
  }
1470
1507
  if (typeof target === "string") {
1471
- target = document.querySelectorAll(target);
1508
+ target = DOMUtilsCore.document.querySelectorAll(target);
1472
1509
  }
1473
1510
  if (target instanceof NodeList || target instanceof Array) {
1474
1511
  target = target;
@@ -1477,6 +1514,7 @@ class DOMUtils {
1477
1514
  }
1478
1515
  }
1479
1516
  else {
1517
+ target = target;
1480
1518
  target.style.display = "none";
1481
1519
  if (CommonDOMUtils.isShow(target)) {
1482
1520
  /* 仍然是显示,尝试使用强覆盖 */
@@ -1505,7 +1543,7 @@ class DOMUtils {
1505
1543
  return;
1506
1544
  }
1507
1545
  if (typeof target === "string") {
1508
- target = document.querySelector(target);
1546
+ target = DOMUtilsCore.document.querySelector(target);
1509
1547
  }
1510
1548
  DOMUtilsContext.on(target, "keyup", null, handler, option);
1511
1549
  }
@@ -1530,7 +1568,7 @@ class DOMUtils {
1530
1568
  return;
1531
1569
  }
1532
1570
  if (typeof target === "string") {
1533
- target = document.querySelector(target);
1571
+ target = DOMUtilsCore.document.querySelector(target);
1534
1572
  }
1535
1573
  DOMUtilsContext.on(target, "keydown", null, handler, option);
1536
1574
  }
@@ -1555,7 +1593,7 @@ class DOMUtils {
1555
1593
  return;
1556
1594
  }
1557
1595
  if (typeof target === "string") {
1558
- target = document.querySelector(target);
1596
+ target = DOMUtilsCore.document.querySelector(target);
1559
1597
  }
1560
1598
  DOMUtilsContext.on(target, "keypress", null, handler, option);
1561
1599
  }
@@ -1578,7 +1616,7 @@ class DOMUtils {
1578
1616
  return;
1579
1617
  }
1580
1618
  if (typeof element === "string") {
1581
- element = document.querySelector(element);
1619
+ element = DOMUtilsCore.document.querySelector(element);
1582
1620
  }
1583
1621
  element = element;
1584
1622
  element.style.opacity = "0";
@@ -1592,16 +1630,16 @@ class DOMUtils {
1592
1630
  element = element;
1593
1631
  element.style.opacity = Math.min(progress / duration, 1).toString();
1594
1632
  if (progress < duration) {
1595
- window.requestAnimationFrame(step);
1633
+ DOMUtilsCore.window.requestAnimationFrame(step);
1596
1634
  }
1597
1635
  else {
1598
1636
  if (callback && typeof callback === "function") {
1599
1637
  callback();
1600
1638
  }
1601
- window.cancelAnimationFrame(timer);
1639
+ DOMUtilsCore.window.cancelAnimationFrame(timer);
1602
1640
  }
1603
1641
  }
1604
- timer = window.requestAnimationFrame(step);
1642
+ timer = DOMUtilsCore.window.requestAnimationFrame(step);
1605
1643
  }
1606
1644
  /**
1607
1645
  * 淡出元素
@@ -1622,7 +1660,7 @@ class DOMUtils {
1622
1660
  return;
1623
1661
  }
1624
1662
  if (typeof element === "string") {
1625
- element = document.querySelector(element);
1663
+ element = DOMUtilsCore.document.querySelector(element);
1626
1664
  }
1627
1665
  element = element;
1628
1666
  element.style.opacity = "1";
@@ -1635,17 +1673,17 @@ class DOMUtils {
1635
1673
  element = element;
1636
1674
  element.style.opacity = Math.max(1 - progress / duration, 0).toString();
1637
1675
  if (progress < duration) {
1638
- window.requestAnimationFrame(step);
1676
+ DOMUtilsCore.window.requestAnimationFrame(step);
1639
1677
  }
1640
1678
  else {
1641
1679
  element.style.display = "none";
1642
1680
  if (typeof callback === "function") {
1643
1681
  callback();
1644
1682
  }
1645
- window.cancelAnimationFrame(timer);
1683
+ DOMUtilsCore.window.cancelAnimationFrame(timer);
1646
1684
  }
1647
1685
  }
1648
- timer = window.requestAnimationFrame(step);
1686
+ timer = DOMUtilsCore.window.requestAnimationFrame(step);
1649
1687
  }
1650
1688
  /**
1651
1689
  * 切换元素的显示和隐藏状态
@@ -1658,7 +1696,7 @@ class DOMUtils {
1658
1696
  toggle(element) {
1659
1697
  let DOMUtilsContext = this;
1660
1698
  if (typeof element === "string") {
1661
- element = document.querySelector(element);
1699
+ element = DOMUtilsCore.document.querySelector(element);
1662
1700
  }
1663
1701
  if (element == null) {
1664
1702
  return;
@@ -1670,6 +1708,14 @@ class DOMUtils {
1670
1708
  DOMUtilsContext.hide(element);
1671
1709
  }
1672
1710
  }
1711
+ /**
1712
+ * 创建一个新的DOMUtils实例
1713
+ * @param option
1714
+ * @returns
1715
+ */
1716
+ createDOMUtils(option) {
1717
+ return new DOMUtils(option);
1718
+ }
1673
1719
  }
1674
1720
  let domUtils = new DOMUtils();
1675
1721