-
-
Notifications
You must be signed in to change notification settings - Fork 205
Expand file tree
/
Copy pathutil.ts
More file actions
43 lines (39 loc) · 1.18 KB
/
util.ts
File metadata and controls
43 lines (39 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// =============================== Motion ===============================
export function getMotionName(prefixCls: string, transitionName?: string, animationName?: string) {
let motionName = transitionName;
if (!motionName && animationName) {
motionName = `${prefixCls}-${animationName}`;
}
return motionName;
}
// =============================== Offset ===============================
function getScroll(w: Window, top?: boolean): number {
let ret = w[`page${top ? 'Y' : 'X'}Offset`];
const method = `scroll${top ? 'Top' : 'Left'}`;
if (typeof ret !== 'number') {
const d = w.document;
ret = d.documentElement[method];
if (typeof ret !== 'number') {
ret = d.body[method];
}
}
return ret;
}
type CompatibleDocument = {
parentWindow?: Window;
} & Document;
export function offset(el: Element) {
const rect = el.getBoundingClientRect();
const pos = {
left: rect.left,
top: rect.top,
};
const doc = el.ownerDocument as CompatibleDocument;
const w = doc.defaultView || doc.parentWindow;
pos.left += getScroll(w);
pos.top += getScroll(w, true);
return pos;
}
export function isNil(val: any) {
return val === undefined || val === null;
}