Skip to content

Commit 984fbe3

Browse files
authored
Merge pull request #35 from xiaohajiayou/dev
Fix: rate button disappear when resize window
2 parents fb5a009 + f025797 commit 984fbe3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/popup/script/submission.js

+21
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,27 @@ export const addRecordButton = () => {
178178

179179
// 添加到页面
180180
document.body.appendChild(button);
181+
182+
// 添加窗口大小变化监听器
183+
window.addEventListener('resize', () => {
184+
const buttonRect = button.getBoundingClientRect();
185+
const maxRight = window.innerWidth - button.offsetWidth - 10;
186+
const maxBottom = window.innerHeight - button.offsetHeight - 10;
187+
188+
// 如果按钮超出可视区域,调整位置
189+
if (parseInt(button.style.right) > maxRight) {
190+
button.style.right = `${maxRight}px`;
191+
}
192+
if (parseInt(button.style.bottom) > maxBottom) {
193+
button.style.bottom = `${maxBottom}px`;
194+
}
195+
196+
// 保存调整后的位置
197+
localStorage.setItem('LMS_rateButtonPosition', JSON.stringify({
198+
bottom: parseInt(button.style.bottom),
199+
right: parseInt(button.style.right)
200+
}));
201+
});
181202
};
182203

183204

0 commit comments

Comments
 (0)