fix: 优化双端输入框失焦交互,点击背景/空白区域退出编辑、关闭键盘
This commit is contained in:
13
js/script.js
13
js/script.js
@@ -75,8 +75,11 @@
|
|||||||
|
|
||||||
// 点击容器空白处取消选中
|
// 点击容器空白处取消选中
|
||||||
imageContainer.addEventListener('click', (e) => {
|
imageContainer.addEventListener('click', (e) => {
|
||||||
// 如果点击的是容器本身或背景图层,取消输入框选中
|
// 点击容器、背景图层或背景图片,取消输入框选中
|
||||||
if (e.target === imageContainer || e.target === bgLayer || e.target === bgImage) {
|
if (e.target === imageContainer ||
|
||||||
|
e.target === bgLayer ||
|
||||||
|
e.target === bgImage ||
|
||||||
|
e.target.closest('.preview-bg-layer')) {
|
||||||
deselectAll();
|
deselectAll();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -140,7 +143,6 @@
|
|||||||
imgWidth = containerWidth;
|
imgWidth = containerWidth;
|
||||||
imgHeight = imgWidth / imgRatio;
|
imgHeight = imgWidth / imgRatio;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算滑动边界:严格以图片边缘为边界,不能露出白板
|
// 计算滑动边界:严格以图片边缘为边界,不能露出白板
|
||||||
// 滑动公式:imageOffsetX = imageStartOffsetX + deltaX
|
// 滑动公式:imageOffsetX = imageStartOffsetX + deltaX
|
||||||
// 手指向右滑动(deltaX>0) → imageOffsetX增大 → 图片右移,显示右侧
|
// 手指向右滑动(deltaX>0) → imageOffsetX增大 → 图片右移,显示右侧
|
||||||
@@ -210,6 +212,11 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果正在编辑,先退出编辑状态
|
||||||
|
if (editingInput) {
|
||||||
|
deselectAll();
|
||||||
|
}
|
||||||
|
|
||||||
// 如果没有图片,不处理
|
// 如果没有图片,不处理
|
||||||
if (!currentImage) {
|
if (!currentImage) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user