Skip to content

Commit 1e10979

Browse files
committed
refactor(flexible): 移除recalibrate选项并优化滚动条处理
1 parent 0f3cc49 commit 1e10979

2 files changed

Lines changed: 8 additions & 13 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-alpha.1",
3+
"version": "0.0.5-alpha.2",
44
"private": false,
55
"keywords": [
66
"flexible"

packages/flexible/src/index.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,6 @@ export interface FlexibleOptions {
7777
* 默认为 [1, 1, ...] (无额外缩放)。
7878
*/
7979
ratio?: number[];
80-
/**
81-
* 是否在窗口大小调整时重新校准布局。
82-
* 因为宽度变化,但是css var没来得及变化导致出现滚动条,clientWidth和innerWidth不一致
83-
* 默认为 true。
84-
*/
85-
recalibrate?: boolean;
8680
/**
8781
* 用于控制 resize 行为的选项。
8882
*/
@@ -111,7 +105,6 @@ export const flexible = (options: FlexibleOptions = {}): (() => void) => {
111105
immediate = false,
112106
orientationchange = true,
113107
ratio: propRatio,
114-
recalibrate = true,
115108
resizeOption,
116109
onInitialized,
117110
} = options;
@@ -120,7 +113,7 @@ export const flexible = (options: FlexibleOptions = {}): (() => void) => {
120113
const basicLayout = propBasicLayout ?? layouts?.at(-1);
121114
const defaultScopeCssVarName = '--local-scope-rem';
122115
// 对于相同设备来说,滚动条要么永远占据宽度,要么永远不占据宽度
123-
const isScrollbarPresent = getScrollbarWidth() > 0;
116+
const scrollbarWidth = getScrollbarWidth();
124117

125118
// 确保 ratio 数组的长度与 layouts 匹配,默认为 1
126119
let ratio = propRatio;
@@ -150,7 +143,9 @@ export const flexible = (options: FlexibleOptions = {}): (() => void) => {
150143
// 内部核心计算逻辑,可以被重复调用
151144
const recalculate = () => {
152145
const width = window.innerWidth; // 用于断点匹配
153-
const effectiveWidth = document.documentElement.clientWidth; // 用于rem计算
146+
// const effectiveWidth = document.documentElement.clientWidth; // 用于rem计算
147+
//TODO: ?没办法去判断滚动条的状态
148+
const effectiveWidth = window.innerWidth - scrollbarWidth;
154149

155150
let vw = effectiveWidth / 100;
156151
let matched = false;
@@ -189,9 +184,9 @@ export const flexible = (options: FlexibleOptions = {}): (() => void) => {
189184
recalculate();
190185
// 第二次计算:请求在浏览器下一次重绘前再次计算。
191186
// 此时,clientWidth已经是重排后的稳定值。
192-
if (recalibrate && isScrollbarPresent) {
193-
requestAnimationFrame(recalculate);
194-
}
187+
// if (recalibrate && isScrollbarPresent) {
188+
// requestAnimationFrame(recalculate);
189+
// }
195190
};
196191

197192
let resizeHandler: () => void = responsive;

0 commit comments

Comments
 (0)