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