lyb-js 1.6.28 → 1.6.29
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/Base/LibJsResizeWatcher.js +5 -22
- package/package.json +1 -1
|
@@ -23,12 +23,8 @@ export class LibJsResizeWatcher {
|
|
|
23
23
|
if (mode === "h" || mode === "v")
|
|
24
24
|
return;
|
|
25
25
|
//初始化时绑定窗口 resize 事件
|
|
26
|
-
window.addEventListener("resize",
|
|
27
|
-
|
|
28
|
-
});
|
|
29
|
-
window.addEventListener("orientationchange", () => {
|
|
30
|
-
requestAnimationFrame(this._handleResize);
|
|
31
|
-
});
|
|
26
|
+
window.addEventListener("resize", this._handleResize);
|
|
27
|
+
window.addEventListener("orientationchange", this._handleResize);
|
|
32
28
|
}
|
|
33
29
|
/**
|
|
34
30
|
* @description 注册一个窗口尺寸变化的监听器
|
|
@@ -41,17 +37,11 @@ export class LibJsResizeWatcher {
|
|
|
41
37
|
const h = window.innerHeight;
|
|
42
38
|
const orientation = w > h ? "h" : "v";
|
|
43
39
|
if (this._mode === "h") {
|
|
44
|
-
immediate &&
|
|
45
|
-
requestAnimationFrame(() => {
|
|
46
|
-
cb(1920, 1080, Math.min(w / 1920, h / 1080));
|
|
47
|
-
});
|
|
40
|
+
immediate && cb(1920, 1080, Math.min(w / 1920, h / 1080));
|
|
48
41
|
return () => { };
|
|
49
42
|
}
|
|
50
43
|
else if (this._mode === "v") {
|
|
51
|
-
immediate &&
|
|
52
|
-
requestAnimationFrame(() => {
|
|
53
|
-
cb(1080, 1920, Math.min(w / 1080, h / 1920));
|
|
54
|
-
});
|
|
44
|
+
immediate && cb(1080, 1920, Math.min(w / 1080, h / 1920));
|
|
55
45
|
return () => { };
|
|
56
46
|
}
|
|
57
47
|
let s;
|
|
@@ -63,10 +53,7 @@ export class LibJsResizeWatcher {
|
|
|
63
53
|
}
|
|
64
54
|
const item = { cb, immediate };
|
|
65
55
|
this._listeners.push(item);
|
|
66
|
-
immediate &&
|
|
67
|
-
requestAnimationFrame(() => {
|
|
68
|
-
cb(window.innerWidth, window.innerHeight, s);
|
|
69
|
-
});
|
|
56
|
+
immediate && cb(window.innerWidth, window.innerHeight, s);
|
|
70
57
|
return () => {
|
|
71
58
|
this._listeners = this._listeners.filter((l) => l !== item);
|
|
72
59
|
};
|
|
@@ -74,10 +61,6 @@ export class LibJsResizeWatcher {
|
|
|
74
61
|
/** 新增方法:通过id注册监听器(若id已存在会先移除旧的) */
|
|
75
62
|
onById(id, cb, immediate = true) {
|
|
76
63
|
this.offById(id);
|
|
77
|
-
const remove = this.on(cb, immediate);
|
|
78
|
-
this._listenerMap.set(id, cb);
|
|
79
|
-
// 存储移除函数
|
|
80
|
-
this._listenerMap.set(`${id}_remove`, remove);
|
|
81
64
|
}
|
|
82
65
|
/** 通过id移除监听器 */
|
|
83
66
|
offById(...ids) {
|