feat: draggable progress bar (seek) and settings sliders

This commit is contained in:
2026-08-17 12:20:05 +08:00
parent 91665bbbd5
commit d1d903278e
4 changed files with 77 additions and 9 deletions
+24 -9
View File
@@ -116,12 +116,10 @@ function setupMask(page) {
window.mask.setEnabled(!window.mask.enabled());
refresh();
};
slider.onclick = (e) => {
const rect = slider.getBoundingClientRect();
const a = Math.min(1, Math.max(0, (e.clientX - rect.left) / rect.width));
makeSliderDraggable(slider, (a) => {
window.mask.setAlpha(Math.round(a * 100) / 100);
refresh();
};
});
}
// 通知使用权授权项:异步查状态,未授权点击跳转系统授权页
@@ -155,12 +153,10 @@ function setupBrightness(page) {
const pct = value / 255 * 100;
sliderEl.style.setProperty('--fill', pct + '%');
sliderEl.querySelector('i').style.left = pct + '%';
sliderEl.onclick = (e) => {
e.stopPropagation();
const rect = sliderEl.getBoundingClientRect();
const v = Math.round(Math.min(255, Math.max(0, (e.clientX - rect.left) / rect.width)) * 255);
makeSliderDraggable(sliderEl, (ratio) => {
const v = Math.round(ratio * 255);
bridge.call('setSystemBrightness', v).then(() => renderSlider(v)).catch(() => {});
};
});
item.appendChild(sliderEl);
};
@@ -237,3 +233,22 @@ function setupCheckUpdate(page) {
});
};
}
// 通用滑块拖动:touch 拖动实时回调(保留 click 兼容桌面调试)
// Generic draggable slider: touch-drag with live callback (click kept for desktop)
function makeSliderDraggable(slider, onRatio) {
let dragging = false;
const ratioAt = (clientX) => {
const rect = slider.getBoundingClientRect();
return Math.min(1, Math.max(0, (clientX - rect.left) / rect.width));
};
slider.addEventListener('touchstart', (e) => {
dragging = true;
onRatio(ratioAt(e.touches[0].clientX));
}, { passive: true });
slider.addEventListener('touchmove', (e) => {
if (dragging) onRatio(ratioAt(e.touches[0].clientX));
}, { passive: true });
slider.addEventListener('touchend', () => { dragging = false; }, { passive: true });
slider.addEventListener('click', (e) => onRatio(ratioAt(e.clientX)));
}