Skip to content

Commit 6334566

Browse files
committed
feat(flexible): 添加onInitialized回调及版本更新至alpha
1 parent dc698d6 commit 6334566

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

packages/flexible/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cherrywind/flexible",
3-
"version": "0.0.5",
3+
"version": "0.0.5.alpha.1",
44
"private": false,
55
"keywords": [
66
"flexible"

packages/flexible/src/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export interface FlexibleOptions {
9292
delay?: number;
9393
}
9494
| false;
95+
onInitialized?: () => void;
9596
}
9697

9798
/**
@@ -112,6 +113,7 @@ export const flexible = (options: FlexibleOptions = {}): (() => void) => {
112113
ratio: propRatio,
113114
recalibrate = true,
114115
resizeOption,
116+
onInitialized,
115117
} = options;
116118
const breakpoints = propBreakpoints;
117119
const layouts = propLayouts;
@@ -204,18 +206,23 @@ export const flexible = (options: FlexibleOptions = {}): (() => void) => {
204206
}
205207
if (immediate) {
206208
responsive();
209+
requestAnimationFrame(() => {
210+
onInitialized?.();
211+
});
207212
} else {
208-
window.addEventListener('load', responsive);
213+
window.addEventListener('load', () => {
214+
responsive();
215+
requestAnimationFrame(() => {
216+
onInitialized?.();
217+
});
218+
});
209219
}
210220
window.addEventListener('resize', resizeHandler);
211221
if (orientationchange) {
212222
screen.orientation.addEventListener('change', resizeHandler);
213223
}
214224
// 返回清理函数
215225
return () => {
216-
if (!immediate) {
217-
window.removeEventListener('load', responsive);
218-
}
219226
window.removeEventListener('resize', resizeHandler);
220227
if (orientationchange) {
221228
screen.orientation.removeEventListener('change', resizeHandler);

0 commit comments

Comments
 (0)