@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.amd.js +39 -7
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +39 -7
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +39 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +39 -7
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +39 -7
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +39 -7
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +8 -2
- package/package.json +1 -1
- package/src/Utils.ts +54 -11
|
@@ -786,12 +786,18 @@ declare class Utils {
|
|
|
786
786
|
isNativeFunc(target: Function): boolean;
|
|
787
787
|
/**
|
|
788
788
|
* 判断当前的位置是否位于页面底部附近
|
|
789
|
-
* @param
|
|
789
|
+
* @param nearBottomHeight (可选)判断在底部的误差值,默认:50
|
|
790
790
|
* @returns
|
|
791
791
|
* + true 在底部附近
|
|
792
792
|
* + false 不在底部附近
|
|
793
793
|
*/
|
|
794
|
-
isNearBottom(
|
|
794
|
+
isNearBottom(nearBottomHeight?: number): boolean;
|
|
795
|
+
/**
|
|
796
|
+
* 判断元素内当前的位置是否位于元素内底部附近
|
|
797
|
+
* @param target 需要判断的元素
|
|
798
|
+
* @param nearBottomHeight (可选)判断在底部的误差值,默认:50
|
|
799
|
+
*/
|
|
800
|
+
isNearBottom(target: HTMLElement, nearBottomHeight?: number): boolean;
|
|
795
801
|
/**
|
|
796
802
|
* 判断对象是否是元素
|
|
797
803
|
* @param target
|
package/package.json
CHANGED
package/src/Utils.ts
CHANGED
|
@@ -1857,21 +1857,64 @@ class Utils {
|
|
|
1857
1857
|
}
|
|
1858
1858
|
/**
|
|
1859
1859
|
* 判断当前的位置是否位于页面底部附近
|
|
1860
|
-
* @param
|
|
1860
|
+
* @param nearBottomHeight (可选)判断在底部的误差值,默认:50
|
|
1861
1861
|
* @returns
|
|
1862
1862
|
* + true 在底部附近
|
|
1863
1863
|
* + false 不在底部附近
|
|
1864
1864
|
*/
|
|
1865
|
-
isNearBottom(
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1865
|
+
isNearBottom(nearBottomHeight?: number): boolean;
|
|
1866
|
+
/**
|
|
1867
|
+
* 判断元素内当前的位置是否位于元素内底部附近
|
|
1868
|
+
* @param target 需要判断的元素
|
|
1869
|
+
* @param nearBottomHeight (可选)判断在底部的误差值,默认:50
|
|
1870
|
+
*/
|
|
1871
|
+
isNearBottom(target: HTMLElement, nearBottomHeight?: number): boolean;
|
|
1872
|
+
isNearBottom(...args: any[]): boolean {
|
|
1873
|
+
let nearBottomHeight = 50;
|
|
1874
|
+
|
|
1875
|
+
let checkWindow = () => {
|
|
1876
|
+
// 已滚动的距离
|
|
1877
|
+
let scrollTop: number =
|
|
1878
|
+
this.windowApi.window.pageYOffset ||
|
|
1879
|
+
this.windowApi.document.documentElement.scrollTop;
|
|
1880
|
+
// 视窗高度
|
|
1881
|
+
let viewportHeight: number =
|
|
1882
|
+
this.windowApi.window.innerHeight ||
|
|
1883
|
+
this.windowApi.document.documentElement.clientHeight;
|
|
1884
|
+
// 最大滚动距离
|
|
1885
|
+
let maxScrollHeight: number =
|
|
1886
|
+
this.windowApi.document.documentElement.scrollHeight - nearBottomHeight;
|
|
1887
|
+
|
|
1888
|
+
return scrollTop + viewportHeight >= maxScrollHeight;
|
|
1889
|
+
};
|
|
1890
|
+
|
|
1891
|
+
let checkNode = ($ele: HTMLElement) => {
|
|
1892
|
+
// 已滚动的距离
|
|
1893
|
+
let scrollTop: number = $ele.scrollTop;
|
|
1894
|
+
// 视窗高度
|
|
1895
|
+
let viewportHeight: number = $ele.clientHeight;
|
|
1896
|
+
// 最大滚动距离
|
|
1897
|
+
let maxScrollHeight: number =
|
|
1898
|
+
$ele.scrollHeight - viewportHeight - nearBottomHeight;
|
|
1899
|
+
|
|
1900
|
+
return scrollTop >= maxScrollHeight;
|
|
1901
|
+
};
|
|
1902
|
+
|
|
1903
|
+
let firstArg = args[0];
|
|
1904
|
+
if (args.length === 0 || typeof args[0] === "number") {
|
|
1905
|
+
// nearBottomHeight
|
|
1906
|
+
//
|
|
1907
|
+
return checkWindow();
|
|
1908
|
+
} else if (typeof args[0] === "object" && args[0] instanceof HTMLElement) {
|
|
1909
|
+
// target
|
|
1910
|
+
// target,nearBottomHeight
|
|
1911
|
+
if (typeof args[1] === "number" && !Number.isNaN(args[1])) {
|
|
1912
|
+
nearBottomHeight = args[1];
|
|
1913
|
+
}
|
|
1914
|
+
return checkNode(args[0]);
|
|
1915
|
+
} else {
|
|
1916
|
+
throw new TypeError("参数1类型错误" + typeof firstArg);
|
|
1917
|
+
}
|
|
1875
1918
|
}
|
|
1876
1919
|
/**
|
|
1877
1920
|
* 判断对象是否是元素
|