@whitesev/utils 2.4.7 → 2.4.8

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.cjs.js CHANGED
@@ -5286,13 +5286,45 @@ class Utils {
5286
5286
  isNativeFunc(target) {
5287
5287
  return Boolean(target.toString().match(/^function .*\(\) { \[native code\] }$/));
5288
5288
  }
5289
- isNearBottom(nearValue = 50) {
5290
- var scrollTop = this.windowApi.window.pageYOffset ||
5291
- this.windowApi.document.documentElement.scrollTop;
5292
- var windowHeight = this.windowApi.window.innerHeight ||
5293
- this.windowApi.document.documentElement.clientHeight;
5294
- var documentHeight = this.windowApi.document.documentElement.scrollHeight;
5295
- return scrollTop + windowHeight >= documentHeight - nearValue;
5289
+ isNearBottom(...args) {
5290
+ let nearBottomHeight = 50;
5291
+ let checkWindow = () => {
5292
+ // 已滚动的距离
5293
+ let scrollTop = this.windowApi.window.pageYOffset ||
5294
+ this.windowApi.document.documentElement.scrollTop;
5295
+ // 视窗高度
5296
+ let viewportHeight = this.windowApi.window.innerHeight ||
5297
+ this.windowApi.document.documentElement.clientHeight;
5298
+ // 最大滚动距离
5299
+ let maxScrollHeight = this.windowApi.document.documentElement.scrollHeight - nearBottomHeight;
5300
+ return scrollTop + viewportHeight >= maxScrollHeight;
5301
+ };
5302
+ let checkNode = ($ele) => {
5303
+ // 已滚动的距离
5304
+ let scrollTop = $ele.scrollTop;
5305
+ // 视窗高度
5306
+ let viewportHeight = $ele.clientHeight;
5307
+ // 最大滚动距离
5308
+ let maxScrollHeight = $ele.scrollHeight - viewportHeight - nearBottomHeight;
5309
+ return scrollTop >= maxScrollHeight;
5310
+ };
5311
+ let firstArg = args[0];
5312
+ if (args.length === 0 || typeof args[0] === "number") {
5313
+ // nearBottomHeight
5314
+ //
5315
+ return checkWindow();
5316
+ }
5317
+ else if (typeof args[0] === "object" && args[0] instanceof HTMLElement) {
5318
+ // target
5319
+ // target,nearBottomHeight
5320
+ if (typeof args[1] === "number" && !Number.isNaN(args[1])) {
5321
+ nearBottomHeight = args[1];
5322
+ }
5323
+ return checkNode(args[0]);
5324
+ }
5325
+ else {
5326
+ throw new TypeError("参数1类型错误" + typeof firstArg);
5327
+ }
5296
5328
  }
5297
5329
  isDOM(target) {
5298
5330
  return target instanceof Node;