From b69bfae1bb7b82d98892a1525c11d77c315409f0 Mon Sep 17 00:00:00 2001 From: Zhukj <3262118957> Date: Sat, 18 Apr 2026 14:35:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E6=A1=86=E5=88=A0=E9=99=A4=E6=8C=89=E9=92=AE=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=88=E8=BF=98=E5=8E=9F=E5=88=B0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- css/style.css | 31 ----------------- index.html | 12 ------- js/script.js | 93 +++++++++++---------------------------------------- 3 files changed, 19 insertions(+), 117 deletions(-) diff --git a/css/style.css b/css/style.css index 7d4ca5a..3a5053a 100644 --- a/css/style.css +++ b/css/style.css @@ -17,7 +17,6 @@ html, body { display: flex; flex-direction: column; height: 100vh; - position: relative; } /* 顶部工具栏 */ @@ -82,10 +81,6 @@ html, body { /* 文本编辑器工具栏 */ .text-editor-toolbar { - position: absolute; - top: 49px; - left: 0; - right: 0; display: flex; justify-content: center; align-items: center; @@ -97,7 +92,6 @@ html, body { visibility: hidden; opacity: 0; transition: opacity 0.2s; - z-index: 100; } .text-editor-toolbar.active { @@ -105,31 +99,6 @@ html, body { opacity: 1; } -/* 图片编辑器工具栏 - 与文本编辑器共享位置 */ -.image-editor-toolbar { - position: absolute; - top: 49px; - left: 0; - right: 0; - display: flex; - justify-content: center; - align-items: center; - gap: 8px; - padding: 10px 16px; - background: #fff; - border-bottom: 1px solid #e0e0e0; - flex-shrink: 0; - visibility: hidden; - opacity: 0; - transition: opacity 0.2s; - z-index: 100; -} - -.image-editor-toolbar.active { - visibility: visible; - opacity: 1; -} - .toolbar-btn { width: 40px; height: 40px; diff --git a/index.html b/index.html index 457d306..105d03c 100644 --- a/index.html +++ b/index.html @@ -46,18 +46,6 @@ - -
- -
-
diff --git a/js/script.js b/js/script.js index c1f5d97..7ab1712 100644 --- a/js/script.js +++ b/js/script.js @@ -15,13 +15,11 @@ const longPressTip = document.getElementById('longPressTip'); const canvasArea = document.getElementById('canvasArea'); const textEditorToolbar = document.getElementById('textEditorToolbar'); - const imageEditorToolbar = document.getElementById('imageEditorToolbar'); const boldBtn = document.getElementById('boldBtn'); const italicBtn = document.getElementById('italicBtn'); const colorPicker = document.getElementById('colorPicker'); const fontPicker = document.getElementById('fontPicker'); const fontSizePicker = document.getElementById('fontSizePicker'); - const opacityPicker = document.getElementById('opacityPicker'); const overlayLayer = document.getElementById('overlayLayer'); const overlayInput = document.createElement('input'); overlayInput.type = 'file'; @@ -144,9 +142,8 @@ } // 隐藏辅助线 hideGuides(); - // 隐藏文本编辑器工具栏和图片编辑器工具栏 + // 隐藏文本编辑器工具栏 textEditorToolbar.classList.remove('active'); - imageEditorToolbar.classList.remove('active'); } // 点击空白区域(不是层叠图和输入框) @@ -310,16 +307,12 @@ let isDragging = false; let isResizing = false; let startX, startY, startLeft, startTop, startWidth, startHeight; - let hasMoved = false; const minSize = 30; // 点击选中(区分点击和拖拽) overlayEl.addEventListener('click', (e) => { e.stopPropagation(); - if (!hasMoved) { - selectOverlay(overlayEl); - } - hasMoved = false; + selectOverlay(overlayEl); }); // 拖拽移动(不选中也可拖动) @@ -336,7 +329,6 @@ const clientY = isTouch ? e.touches[0].clientY : e.clientY; isDragging = true; - hasMoved = false; startX = clientX; startY = clientY; startLeft = overlayEl.offsetLeft; @@ -344,6 +336,7 @@ overlayEl.classList.add('dragging'); + // 拖动时设置为选中状态 selectOverlay(overlayEl); document.addEventListener('mousemove', handleDragMove); @@ -364,10 +357,21 @@ const moveDistance = Math.sqrt(dx * dx + dy * dy); if (moveDistance > 5) { - hasMoved = true; let newLeft = startLeft + dx; let newTop = startTop + dy; + // 使用吸附功能 + const snapped = getSnapPosition(overlayEl, newLeft, newTop); + newLeft = snapped.left; + newTop = snapped.top; + + // 显示对齐辅助线 + if (snapped.showGuide) { + showAlignmentGuides(overlayEl); + } else { + hideGuides(); + } + overlayEl.style.left = newLeft + 'px'; overlayEl.style.top = newTop + 'px'; } @@ -378,6 +382,7 @@ function handleDragEnd() { isDragging = false; overlayEl.classList.remove('dragging'); + hideGuides(); document.removeEventListener('mousemove', handleDragMove); document.removeEventListener('mouseup', handleDragEnd); @@ -501,15 +506,6 @@ } selectedOverlay = overlayEl; overlayEl.classList.add('selected'); - - // 显示图片编辑器工具栏,隐藏文本编辑器工具栏 - imageEditorToolbar.classList.add('active'); - textEditorToolbar.classList.remove('active'); - - // 更新透明度值显示 - const currentOpacity = Math.round(parseFloat(overlayEl.style.opacity || 1) * 100); - opacityValue = currentOpacity; - opacityValueEl.textContent = currentOpacity; } // 计算图片滑动边界 @@ -601,11 +597,6 @@ return; } - // 如果点击的是层叠图,不处理图片滑动(让层叠图的拖拽处理) - if (e.target.closest('.overlay-image')) { - return; - } - // 如果正在编辑,先退出编辑状态 if (editingInput) { deselectAll(); @@ -846,9 +837,8 @@ element.classList.remove('editing'); element.contentEditable = 'false'; - // 显示文本编辑器工具栏,隐藏图片编辑器工具栏 + // 显示文本编辑器工具栏 textEditorToolbar.classList.add('active'); - imageEditorToolbar.classList.remove('active'); // 更新工具栏状态 updateToolbarState(element); @@ -867,9 +857,8 @@ element.classList.remove('selected'); element.contentEditable = 'true'; - // 显示文本编辑器工具栏,隐藏图片编辑器工具栏 + // 显示文本编辑器工具栏 textEditorToolbar.classList.add('active'); - imageEditorToolbar.classList.remove('active'); // 更新工具栏状态 updateToolbarState(element); @@ -1325,13 +1314,8 @@ selectedInput.classList.remove('selected'); selectedInput = null; } - if (selectedOverlay) { - selectedOverlay.classList.remove('selected'); - selectedOverlay = null; - } - // 隐藏所有工具栏 + // 隐藏文本编辑器工具栏 textEditorToolbar.classList.remove('active'); - imageEditorToolbar.classList.remove('active'); } // 初始化长按保存(只在3:5预览区域) @@ -1484,45 +1468,6 @@ updateFontSize(currentSize + delta, true); } }, { passive: false }); - - // 透明度选择器 - 密码锁式滚轮 - let opacityValue = 100; - const opacityRoller = document.getElementById('opacityPicker'); - const opacityValueEl = opacityRoller.querySelector('.roller-value'); - const opacityUpBtn = opacityRoller.querySelector('.roller-up'); - const opacityDownBtn = opacityRoller.querySelector('.roller-down'); - - function updateOpacity(newOpacity, forceUpdate = false) { - newOpacity = Math.max(0, Math.min(100, newOpacity)); - if (selectedOverlay) { - selectedOverlay.style.opacity = newOpacity / 100; - opacityValue = newOpacity; - opacityValueEl.textContent = newOpacity; - } else { - opacityValue = newOpacity; - opacityValueEl.textContent = newOpacity; - } - } - - opacityUpBtn.addEventListener('click', () => { - if (selectedOverlay) { - updateOpacity(opacityValue + 5, true); - } - }); - - opacityDownBtn.addEventListener('click', () => { - if (selectedOverlay) { - updateOpacity(opacityValue - 5, true); - } - }); - - opacityRoller.addEventListener('wheel', (e) => { - e.preventDefault(); - if (selectedOverlay) { - const delta = e.deltaY > 0 ? -5 : 5; - updateOpacity(opacityValue + delta, true); - } - }, { passive: false }); } // 显示右键菜单