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