feat(editor): add text locking support and mobile toolbar scroll
This commit is contained in:
28
js/script.js
28
js/script.js
@@ -27,6 +27,7 @@
|
||||
const bgOpacityValue = document.getElementById('bgOpacityValue');
|
||||
const boldBtn = document.getElementById('boldBtn');
|
||||
const italicBtn = document.getElementById('italicBtn');
|
||||
const lockBtn = document.getElementById('lockBtn');
|
||||
const colorPicker = document.getElementById('colorPicker');
|
||||
const fontPicker = document.getElementById('fontPicker');
|
||||
const fontSizePicker = document.getElementById('fontSizePicker');
|
||||
@@ -971,6 +972,11 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果已锁定,禁止拖拽
|
||||
if (element.classList.contains('locked')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isMouseDown) return;
|
||||
if (!selectedInput) return;
|
||||
|
||||
@@ -1216,6 +1222,9 @@
|
||||
fontPicker.value = fontPicker.options[0].value;
|
||||
}
|
||||
|
||||
// 更新锁定按钮状态
|
||||
lockBtn.classList.toggle('active', element.classList.contains('locked'));
|
||||
|
||||
// 更新字号选择器
|
||||
const fontSizeValueEl = fontSizePicker.querySelector('.roller-value');
|
||||
if (fontSizeValueEl) {
|
||||
@@ -1723,6 +1732,20 @@
|
||||
}
|
||||
});
|
||||
|
||||
// 锁定按钮
|
||||
lockBtn.addEventListener('click', () => {
|
||||
const targetInput = editingInput || selectedInput;
|
||||
if (!targetInput) return;
|
||||
|
||||
const isLocked = targetInput.classList.contains('locked');
|
||||
if (isLocked) {
|
||||
targetInput.classList.remove('locked');
|
||||
} else {
|
||||
targetInput.classList.add('locked');
|
||||
}
|
||||
lockBtn.classList.toggle('active', !isLocked);
|
||||
});
|
||||
|
||||
// 颜色选择器
|
||||
colorPicker.addEventListener('input', () => {
|
||||
const targetInput = editingInput || selectedInput;
|
||||
@@ -1800,6 +1823,11 @@
|
||||
const targetEl = selectedInput || selectedOverlay;
|
||||
if (!targetEl) return;
|
||||
|
||||
// 如果已锁定,禁止键盘微调
|
||||
if (targetEl.classList.contains('locked')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 防止默认行为(页面滚动)
|
||||
if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(e.key)) {
|
||||
e.preventDefault();
|
||||
|
||||
Reference in New Issue
Block a user