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