diff --git a/css/style.css b/css/style.css index 9a62c9b..e5f66aa 100644 --- a/css/style.css +++ b/css/style.css @@ -241,6 +241,20 @@ html, body { margin: 0; } +/* 旋转度数显示固定宽度 */ +#rotateValue { + display: inline-block; + min-width: 40px; + text-align: center; +} + +/* 百分比显示固定宽度 */ +#opacityValue, #bgScaleValue, #bgOpacityValue { + display: inline-block; + min-width: 40px; + text-align: center; +} + /* 字号滚轮选择器 */ .roller-picker { display: flex; diff --git a/js/script.js b/js/script.js index 48c1bc9..617505d 100644 --- a/js/script.js +++ b/js/script.js @@ -130,7 +130,21 @@ // 旋转滑块 rotateSlider.addEventListener('input', (e) => { if (selectedOverlay) { - const rotateDeg = e.target.value; + let rotateDeg = parseInt(e.target.value); + + // 吸附功能:在 0°、-90°、90° 附近吸附 + const snapAngles = [0, -90, 90]; + const snapThreshold = 5; // 吸附阈值 5 度 + + for (const snapAngle of snapAngles) { + if (Math.abs(rotateDeg - snapAngle) < snapThreshold) { + rotateDeg = snapAngle; + // 更新滑动条位置 + rotateSlider.value = rotateDeg; + break; + } + } + selectedOverlay.style.transform = `rotate(${rotateDeg}deg)`; rotateValue.textContent = rotateDeg + '°'; }