nhanh-pure-function 1.2.7 → 1.2.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/lib/User.d.ts +4 -4
- package/lib/User.js +35 -10
- package/package.json +1 -1
package/lib/User.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @param {
|
|
2
|
+
* 滚动结束监听器
|
|
3
|
+
* @param {(trigger?: "vertical" | "horizontal") => void} callback
|
|
4
4
|
*/
|
|
5
|
-
export function
|
|
6
|
-
callback:
|
|
5
|
+
export function _ScrollEndListener(
|
|
6
|
+
callback: (trigger?: "vertical" | "horizontal") => void
|
|
7
7
|
): (payload: Event) => void;
|
|
8
8
|
|
|
9
9
|
/**
|
package/lib/User.js
CHANGED
|
@@ -1,21 +1,46 @@
|
|
|
1
1
|
import { _IsObject, _NotNull, _Debounce } from "./Utility";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* @param {
|
|
4
|
+
* 滚动结束监听器
|
|
5
|
+
* @param {(trigger: "vertical" | "horizontal") => void} callback
|
|
6
6
|
*/
|
|
7
|
-
export function
|
|
7
|
+
export function _ScrollEndListener(callback) {
|
|
8
8
|
const debouncedCallback = _Debounce(callback, 100);
|
|
9
9
|
let lastScrollTop = 0;
|
|
10
|
+
let lastScrollLeft = 0;
|
|
10
11
|
return function (payload) {
|
|
11
12
|
const target = payload.target;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
if (!target) return;
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
scrollTop,
|
|
17
|
+
scrollHeight,
|
|
18
|
+
clientHeight,
|
|
19
|
+
scrollLeft,
|
|
20
|
+
scrollWidth,
|
|
21
|
+
clientWidth,
|
|
22
|
+
} = target;
|
|
23
|
+
function vertical() {
|
|
24
|
+
if (lastScrollTop == scrollTop) return;
|
|
25
|
+
/** 向上滚动? */
|
|
26
|
+
const isUp = lastScrollTop > scrollTop;
|
|
27
|
+
lastScrollTop = scrollTop;
|
|
28
|
+
if (isUp) return;
|
|
29
|
+
const bottom = scrollHeight - scrollTop - clientHeight;
|
|
30
|
+
if (bottom <= 1) debouncedCallback("vertical");
|
|
31
|
+
}
|
|
32
|
+
function horizontal() {
|
|
33
|
+
if (lastScrollLeft == scrollLeft) return;
|
|
34
|
+
/** 向左滚动? */
|
|
35
|
+
const isLeft = lastScrollLeft > scrollLeft;
|
|
36
|
+
lastScrollLeft = scrollLeft;
|
|
37
|
+
if (isLeft) return;
|
|
38
|
+
const right = scrollWidth - scrollLeft - clientWidth;
|
|
39
|
+
if (right <= 1) debouncedCallback("horizontal");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
vertical();
|
|
43
|
+
horizontal();
|
|
19
44
|
};
|
|
20
45
|
}
|
|
21
46
|
|