@whitesev/utils 1.7.0 → 1.8.0

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/dist/index.umd.js CHANGED
@@ -3439,7 +3439,7 @@
3439
3439
  UtilsCore.init(option);
3440
3440
  }
3441
3441
  /** 版本号 */
3442
- version = "2024.6.16";
3442
+ version = "2024.7.20";
3443
3443
  addStyle(cssText) {
3444
3444
  if (typeof cssText !== "string") {
3445
3445
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");
@@ -4133,21 +4133,31 @@
4133
4133
  }
4134
4134
  }
4135
4135
  getMaxZIndex(deviation = 1) {
4136
- let nodeIndexList = [];
4137
4136
  deviation = Number.isNaN(deviation) ? 1 : deviation;
4138
- document.querySelectorAll("*").forEach((element) => {
4137
+ // 最大值2147483647
4138
+ let maxZIndex = Math.pow(2, 31) - 1;
4139
+ // 比较值2000000000
4140
+ let maxZIndexCompare = 2 * Math.pow(10, 9);
4141
+ // 当前页面最大的z-index
4142
+ let zIndex = 0;
4143
+ document.querySelectorAll("*").forEach((element, index) => {
4139
4144
  let nodeStyle = window.getComputedStyle(element);
4140
4145
  /* 不对position为static和display为none的元素进行获取它们的z-index */
4141
4146
  if (nodeStyle.position !== "static" && nodeStyle.display !== "none") {
4142
- nodeIndexList = nodeIndexList.concat(parseInt(nodeStyle.zIndex));
4147
+ let nodeZIndex = parseInt(nodeStyle.zIndex);
4148
+ if (!isNaN(nodeZIndex)) {
4149
+ if (nodeZIndex > zIndex) {
4150
+ zIndex = nodeZIndex;
4151
+ }
4152
+ }
4143
4153
  }
4144
4154
  });
4145
- /* 过滤非Boolean类型 */
4146
- nodeIndexList = nodeIndexList.filter(Boolean);
4147
- let currentMaxZIndex = nodeIndexList.length
4148
- ? Math.max(...nodeIndexList)
4149
- : 0;
4150
- return currentMaxZIndex + deviation;
4155
+ zIndex += deviation;
4156
+ if (zIndex >= maxZIndexCompare) {
4157
+ // 最好不要超过最大值
4158
+ zIndex = maxZIndex;
4159
+ }
4160
+ return zIndex;
4151
4161
  }
4152
4162
  getMinValue(...args) {
4153
4163
  let result = [...args];