@whitesev/utils 2.2.2 → 2.2.4

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.
@@ -5289,6 +5289,41 @@ var Utils = (function () {
5289
5289
  }
5290
5290
  return mutationObserver;
5291
5291
  }
5292
+ /**
5293
+ * 使用观察器观察元素出现在视图内,出现的话触发回调
5294
+ * @param target 目标元素
5295
+ * @param callback 触发的回调
5296
+ * @param options 观察器配置
5297
+ */
5298
+ mutationVisible(target, callback, options) {
5299
+ if (typeof IntersectionObserver === "undefined") {
5300
+ throw new TypeError("IntersectionObserver is not defined");
5301
+ }
5302
+ if (target == null) {
5303
+ throw new TypeError("mutatuinVisible target is null");
5304
+ }
5305
+ let defaultOptions = {
5306
+ root: null,
5307
+ rootMargin: "0px 0px 0px 0px",
5308
+ threshold: [0.01, 0.99],
5309
+ };
5310
+ defaultOptions = this.assign(defaultOptions, options || {});
5311
+ let intersectionObserver = new IntersectionObserver((entries, observer) => {
5312
+ if (entries[0].isIntersecting) {
5313
+ if (typeof callback === "function") {
5314
+ callback(entries, observer);
5315
+ }
5316
+ }
5317
+ }, defaultOptions);
5318
+ if (Array.isArray(target)) {
5319
+ target.forEach((item) => {
5320
+ intersectionObserver.observe(item);
5321
+ });
5322
+ }
5323
+ else {
5324
+ intersectionObserver.observe(target);
5325
+ }
5326
+ }
5292
5327
  /**
5293
5328
  * 去除全局window下的Utils,返回控制权
5294
5329
  * @example