fix(android): refine ai-speaker player interaction and layout
- Replace the always-visible horizontal volume slider with a speaker icon and a vertical overlay panel. Opening the panel focuses the slider: up/down adjusts volume by 1, OK closes it. The icon is sized like the mode button and absolutely positioned on the left so it does not disturb the centered prev/play/next group. - Keep player_status as the single source of truth while preventing stale server source values from overriding an optimistic track switch. A short pendingSource freeze keeps the list highlight from bouncing back to the previous row during the server transition. - Avoid full list rebuilds on playback state changes. Existing rows are updated in place through refreshPlayingMark, preventing focus loss and repeated entrance animations. - Show a loading overlay during initial load and manual refresh with an 8s timeout. Replace CSS inset with explicit positioning for WebView 84, and avoid filter on the gradient play button which made it disappear. - Remove duplicate time text under the progress bar; duration and remaining time are already shown above it. - Clicking the already-playing row is a no-op instead of restarting. All changes were exercised through the hub snapshot on the TV device.
This commit is contained in:
1 parent
998327df53
commit
d07ab09fca
1 file changed
+257
-195
@@ -211,75 +211,103 @@ body {
|
||||
background: linear-gradient(90deg, #4ade80, #38bdf8);
|
||||
transition: width .9s linear;
|
||||
}
|
||||
/* ---- 音量 ---- */
|
||||
#vol-block {
|
||||
width: 100%;
|
||||
/* ---- 音量:图标按钮 + 竖向浮层面板 ---- */
|
||||
/* 尺寸与三档循环一致(5.4vh),并用绝对定位钉在最左侧,
|
||||
不参与主控三键的居中计算,避免影响它们的样式与间距。 */
|
||||
.ctrl-btn.ctrl-vol {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
bottom: 0; /* 与右侧三档键一致的底部对齐 */
|
||||
top: auto;
|
||||
transform: none;
|
||||
width: 5.4vh;
|
||||
height: 5.4vh;
|
||||
font-size: 2.2vh;
|
||||
}
|
||||
.ctrl-btn.ctrl-vol.active {
|
||||
color: var(--accent);
|
||||
border-color: var(--line-hard);
|
||||
background: rgba(76, 201, 240, .14);
|
||||
}
|
||||
|
||||
#vol-pop {
|
||||
position: absolute;
|
||||
left: 1.6vw;
|
||||
bottom: 11vh;
|
||||
z-index: 20;
|
||||
width: 6.4vh;
|
||||
padding: 1vh 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.6vh;
|
||||
flex: 0 0 auto;
|
||||
align-items: center;
|
||||
gap: 0.8vh;
|
||||
border-radius: var(--radius-md);
|
||||
background: rgba(17, 28, 51, .97);
|
||||
border: 1px solid var(--line-mid);
|
||||
box-shadow: 0 1vh 3vh rgba(0, 0, 0, .55);
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
transform: translateY(0.6vh);
|
||||
transition: opacity .16s ease, transform .16s ease, visibility .16s;
|
||||
}
|
||||
#vol-head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
font-size: 1.3vh; color: #7d8fb0;
|
||||
#vol-pop.show {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
transform: translateY(0);
|
||||
}
|
||||
#vol-head .val { font-weight: 700; color: #a9bcda; }
|
||||
|
||||
#vol-bar {
|
||||
#vol-pop-val {
|
||||
font-size: 1.5vh;
|
||||
font-weight: 700;
|
||||
color: var(--accent);
|
||||
font-variant-numeric: tabular-nums;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
#vol-track {
|
||||
position: relative;
|
||||
height: 1.5vh; /* 2.4 -> 1.5,缩小 */
|
||||
width: 1.5vh;
|
||||
height: 18vh;
|
||||
border-radius: 99vh;
|
||||
background: rgba(148,163,184,.17);
|
||||
background: rgba(120, 160, 220, .16);
|
||||
outline: none;
|
||||
cursor: pointer;
|
||||
touch-action: none;
|
||||
/* 关键:不加 outline:none 时,遥控器聚焦会出现浏览器默认的
|
||||
黄色/橙色焦点环,与深蓝主题极度违和 */
|
||||
outline: none;
|
||||
border: 1px solid transparent;
|
||||
transition: border-color .15s, background .15s;
|
||||
}
|
||||
/* WebView 旧版还会画默认 focus-visible 环,显式压掉 */
|
||||
#vol-bar:focus,
|
||||
#vol-bar:focus-visible {
|
||||
#vol-track:focus,
|
||||
#vol-track:focus-visible {
|
||||
outline: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
#vol-fill {
|
||||
position: absolute; top: 0; bottom: 0; left: 0;
|
||||
width: 0%;
|
||||
border-radius: 99vh;
|
||||
background: linear-gradient(90deg, #3ec4f8, #818cf8);
|
||||
pointer-events: none;
|
||||
}
|
||||
#vol-knob {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 0%;
|
||||
width: 2.9vh; height: 2.9vh;
|
||||
margin-left: -1.45vh;
|
||||
margin-top: -1.45vh;
|
||||
border-radius: 50%;
|
||||
background: #eaf6ff;
|
||||
border: 0.25vh solid #3ec4f8;
|
||||
box-shadow: 0 0.3vh 1vh rgba(0,0,0,.55);
|
||||
pointer-events: none;
|
||||
transition: transform .1s ease;
|
||||
}
|
||||
#vol-bar.dragging #vol-knob { transform: scale(1.18); }
|
||||
|
||||
/* 遥控器调节态:整条高亮 + 手柄放大常亮 */
|
||||
#vol-bar.adjusting {
|
||||
background: rgba(62,196,248,.28);
|
||||
box-shadow: 0 0 0 0.25vh rgba(62,196,248,.55), 0 0 2vh rgba(62,196,248,.28);
|
||||
/* 竖向填充:从底部往上 */
|
||||
#vol-track-fill {
|
||||
position: absolute;
|
||||
left: 0; right: 0; bottom: 0;
|
||||
height: 15%;
|
||||
border-radius: 99vh;
|
||||
background: linear-gradient(0deg, #4cc9f0, #6a8dff);
|
||||
pointer-events: none;
|
||||
transition: height .12s linear;
|
||||
}
|
||||
#vol-bar.adjusting #vol-knob {
|
||||
transform: scale(1.22);
|
||||
background: #ffffff;
|
||||
box-shadow: 0 0 1.4vh rgba(62,196,248,.9);
|
||||
#vol-track-knob {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
bottom: 15%;
|
||||
width: 2.4vh; height: 2.4vh;
|
||||
margin-left: -1.2vh;
|
||||
margin-bottom: -1.2vh;
|
||||
border-radius: 50%;
|
||||
background: #fff;
|
||||
border: 0.25vh solid var(--accent);
|
||||
box-shadow: 0 0.3vh 1vh rgba(0, 0, 0, .6);
|
||||
pointer-events: none;
|
||||
transition: bottom .12s linear;
|
||||
}
|
||||
#vol-track.adjusting #vol-track-knob {
|
||||
transform: scale(1.15);
|
||||
box-shadow: 0 0 1.4vh rgba(76, 201, 240, .9);
|
||||
}
|
||||
/* 音量数值在调节态发光 */
|
||||
#vol-block.adj #vol-label { color: #7dd3fc; text-shadow: 0 0 1vh rgba(62,196,248,.8); }
|
||||
|
||||
flex: 1 1 0;
|
||||
padding: 0.65vh 0.3vw;
|
||||
@@ -309,6 +337,11 @@ body {
|
||||
justify-content: center;
|
||||
gap: 1.2vh;
|
||||
width: 100%;
|
||||
/* 左右各有一个绝对定位按钮(音量 / 播放方式),
|
||||
留出等量内边距,保证中间三键仍相对整行居中 */
|
||||
padding-left: 6.2vh;
|
||||
padding-right: 6.2vh;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* 播放方式按钮:绝对定位挂在右侧,不参与主组的居中计算,
|
||||
@@ -627,25 +660,29 @@ body {
|
||||
<div id="prog-bar"><div id="prog-fill"></div></div>
|
||||
</div>
|
||||
|
||||
<div id="vol-block">
|
||||
<div id="vol-head">
|
||||
<span>音量</span>
|
||||
<span class="val" id="vol-label">15 / 100</span>
|
||||
</div>
|
||||
<div id="vol-bar" tabindex="0" role="slider" aria-label="音量" aria-valuemin="0" aria-valuemax="80" aria-valuenow="15">
|
||||
<div id="vol-fill"></div>
|
||||
<div id="vol-knob"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="left-foot">
|
||||
<div id="control-row">
|
||||
<button class="ctrl-btn ctrl-vol" id="btn-vol" title="音量" aria-label="音量设置">
|
||||
<svg viewBox="0 0 24 24" width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 9.5v5h3.2L12 18.6V5.4L7.2 9.5z"/><path d="M16 8.6a4.6 4.6 0 0 1 0 6.8"/><path d="M18.6 6a8 8 0 0 1 0 12"/></svg>
|
||||
</button>
|
||||
<button class="ctrl-btn" id="btn-prev" title="上一首" aria-label="上一首"><svg viewBox="0 0 24 24" width="1em" height="1em" fill="currentColor"><path d="M6 6h2.4v12H6zm3.6 6L18 6.6v10.8z"/></svg></button>
|
||||
<button class="ctrl-btn ctrl-main" id="btn-toggle" title="播放/暂停" aria-label="播放或暂停"><svg viewBox="0 0 24 24" width="1em" height="1em" fill="currentColor"><path d="M8 5.2v13.6L19 12z"/></svg></button>
|
||||
<button class="ctrl-btn" id="btn-next" title="下一首" aria-label="下一首"><svg viewBox="0 0 24 24" width="1em" height="1em" fill="currentColor"><path d="M15.6 6H18v12h-2.4zM14.4 12 6 17.4V6.6z"/></svg></button>
|
||||
<button class="ctrl-btn ctrl-mode" id="btn-mode" title="播放方式" aria-label="播放方式"><svg viewBox="0 0 24 24" width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 2l3 3-3 3"/><path d="M3 11V9a4 4 0 0 1 4-4h13"/><path d="M7 22l-3-3 3-3"/><path d="M21 13v2a4 4 0 0 1-4 4H4"/></svg></button>
|
||||
</div>
|
||||
|
||||
<!-- 竖向音量面板:点音量图标展开,OK 收起 -->
|
||||
<div id="vol-pop" aria-hidden="true">
|
||||
<div id="vol-pop-val">15</div>
|
||||
<div id="vol-track" tabindex="0" role="slider" aria-label="音量"
|
||||
aria-valuemin="0" aria-valuemax="100" aria-valuenow="15">
|
||||
<div id="vol-track-fill"></div>
|
||||
<div id="vol-track-knob"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="log-line">就绪</div>
|
||||
</div>
|
||||
</section>
|
||||
@@ -725,7 +762,8 @@ body {
|
||||
// 切歌冻结:从点击到服务端确认之间,禁止 syncPlayerStatus 覆盖本地 source,
|
||||
// 否则会出现「高亮切过去 → 被旧状态拉回 → 再跳回」的三段闪烁
|
||||
pendingSource: null,
|
||||
pendingUntil: 0
|
||||
pendingUntil: 0,
|
||||
volPanelOpen: false
|
||||
};
|
||||
|
||||
/* ============ 日志 / 状态 ============ */
|
||||
@@ -1246,17 +1284,60 @@ body {
|
||||
|
||||
/* ============ 渲染 ============ */
|
||||
function renderVolume() {
|
||||
var pct = (state.volume / VOL_MAX) * 100;
|
||||
var f = $("vol-fill");
|
||||
if (f) f.style.width = Math.max(0, Math.min(100, pct)) + "%";
|
||||
var k = $("vol-knob");
|
||||
if (k) k.style.left = Math.max(0, Math.min(100, pct)) + "%";
|
||||
var l = $("vol-label");
|
||||
if (l) l.textContent = state.volume + " / " + VOL_MAX;
|
||||
var kb = $("vol-knob");
|
||||
if (kb) FX.volumePulse(kb);
|
||||
var bar = $("vol-bar");
|
||||
if (bar) bar.setAttribute("aria-valuenow", String(state.volume));
|
||||
var pct = Math.max(0, Math.min(100, (state.volume / VOL_MAX) * 100));
|
||||
|
||||
// 竖向面板:填充从底部往上长,手柄跟着走
|
||||
var f = $("vol-track-fill");
|
||||
if (f) f.style.height = pct + "%";
|
||||
var k = $("vol-track-knob");
|
||||
if (k) {
|
||||
k.style.bottom = pct + "%";
|
||||
FX.volumePulse(k);
|
||||
}
|
||||
|
||||
// 数值
|
||||
var v = $("vol-pop-val");
|
||||
if (v) v.textContent = String(state.volume);
|
||||
|
||||
var t = $("vol-track");
|
||||
if (t) t.setAttribute("aria-valuenow", String(state.volume));
|
||||
}
|
||||
|
||||
/* ---- 音量面板开关 ---- */
|
||||
function openVolPanel() {
|
||||
var pop = $("vol-pop");
|
||||
var btn = $("btn-vol");
|
||||
if (!pop) return;
|
||||
pop.classList.add("show");
|
||||
pop.setAttribute("aria-hidden", "false");
|
||||
if (btn) btn.classList.add("active");
|
||||
state.volPanelOpen = true;
|
||||
state.volAdjusting = true;
|
||||
syncVolMode();
|
||||
// 焦点移到竖向滑轨,方便直接按上下键
|
||||
var trk = $("vol-track");
|
||||
if (trk) {
|
||||
collect();
|
||||
focIdx = foc.indexOf(trk);
|
||||
if (focIdx >= 0) setFocus(trk);
|
||||
trk.classList.add("adjusting");
|
||||
}
|
||||
log("音量 " + state.volume + ":↑↓ 调节,OK 收起", "");
|
||||
}
|
||||
|
||||
function closeVolPanel() {
|
||||
var pop = $("vol-pop");
|
||||
var btn = $("btn-vol");
|
||||
if (!pop) return;
|
||||
pop.classList.remove("show");
|
||||
pop.setAttribute("aria-hidden", "true");
|
||||
if (btn) btn.classList.remove("active");
|
||||
state.volPanelOpen = false;
|
||||
state.volAdjusting = false;
|
||||
syncVolMode();
|
||||
var trk = $("vol-track");
|
||||
if (trk) trk.classList.remove("adjusting");
|
||||
log("音量 " + state.volume, "ok");
|
||||
}
|
||||
|
||||
function fmtDur(sec) {
|
||||
@@ -1447,7 +1528,7 @@ body {
|
||||
function collect() {
|
||||
// 注意:.btn 是旧样式,新控制按钮用 .ctrl-btn / .icon-btn,必须一并纳入,
|
||||
// 否则遥控器方向键无法把焦点移动到上一首/下一首/播放方式等按钮。
|
||||
var nodes = document.querySelectorAll(".track, .btn, .ctrl-btn, .icon-btn, #vol-bar");
|
||||
var nodes = document.querySelectorAll(".track, .btn, .ctrl-btn, .icon-btn");
|
||||
foc = Array.prototype.slice.call(nodes).filter(function (el) {
|
||||
if (el.disabled) return false;
|
||||
var r = el.getBoundingClientRect();
|
||||
@@ -1513,46 +1594,43 @@ body {
|
||||
|
||||
window.__pwRemoteKey = function (dir) {
|
||||
collect();
|
||||
var volBar = $("vol-bar");
|
||||
var volTrk = $("vol-track");
|
||||
var volBtn = $("btn-vol");
|
||||
|
||||
// ---- 音量条特处理:聚焦后按 OK 进入调节态,左右键 ±VOL_STEP ----
|
||||
if (volBar) {
|
||||
var volFocused = (foc[focIdx] === volBar);
|
||||
|
||||
if (dir === "ok") {
|
||||
if (volFocused) {
|
||||
// 已在音量条上:切换「调节态」
|
||||
state.volAdjusting = !state.volAdjusting;
|
||||
syncVolMode();
|
||||
if (state.volAdjusting) log("音量调节模式:← -" + VOL_STEP + " → +" + VOL_STEP, "");
|
||||
return true;
|
||||
}
|
||||
var cur = foc[focIdx];
|
||||
if (!cur) { focusFirst(); return true; }
|
||||
cur.click();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (volFocused && state.volAdjusting && (dir === "left" || dir === "right")) {
|
||||
var delta = (dir === "right" ? VOL_STEP : -VOL_STEP);
|
||||
// ============ 音量面板已展开:上下键调音量,OK 收起 ============
|
||||
if (state.volPanelOpen) {
|
||||
if (dir === "up" || dir === "down") {
|
||||
var delta = (dir === "up" ? VOL_STEP : -VOL_STEP);
|
||||
setVolume(state.volume + delta);
|
||||
return true;
|
||||
}
|
||||
if (dir === "ok") {
|
||||
closeVolPanel();
|
||||
return true;
|
||||
}
|
||||
// 其他方向键:先收起面板再交给常规导航
|
||||
closeVolPanel();
|
||||
return true;
|
||||
}
|
||||
|
||||
// 离开音量条时退出调节态
|
||||
if (state.volAdjusting && dir !== "ok" && (!volBar || foc[focIdx] !== volBar)) {
|
||||
state.volAdjusting = false;
|
||||
syncVolMode();
|
||||
// ============ OK 键 ============
|
||||
if (dir === "ok") {
|
||||
var cur = foc[focIdx];
|
||||
if (!cur) { focusFirst(); return true; }
|
||||
// 焦点在音量图标上 -> 展开面板(不触发 click,避免又开又关)
|
||||
if (cur === volBtn) {
|
||||
openVolPanel();
|
||||
return true;
|
||||
}
|
||||
cur.click();
|
||||
return true;
|
||||
}
|
||||
|
||||
// ============ 方向键导航 ============
|
||||
var next = nextInDir(dir);
|
||||
if (next) {
|
||||
setFocus(next);
|
||||
focIdx = foc.indexOf(next);
|
||||
// 焦点进入音量条时自动进入调节态,省一步
|
||||
state.volAdjusting = (next === volBar);
|
||||
syncVolMode();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1564,14 +1642,12 @@ body {
|
||||
return false;
|
||||
};
|
||||
|
||||
/* 音量条调节态的视觉反馈 */
|
||||
/* 音量调节态的视觉反馈 */
|
||||
function syncVolMode() {
|
||||
var bar = $("vol-bar");
|
||||
if (!bar) return;
|
||||
if (state.volAdjusting) bar.classList.add("adjusting");
|
||||
else bar.classList.remove("adjusting");
|
||||
var blk = $("vol-block");
|
||||
if (blk) { if (state.volAdjusting) blk.classList.add("adj"); else blk.classList.remove("adj"); }
|
||||
var trk = $("vol-track");
|
||||
if (!trk) return;
|
||||
if (state.volAdjusting) trk.classList.add("adjusting");
|
||||
else trk.classList.remove("adjusting");
|
||||
}
|
||||
|
||||
window.__pwFocusFirst = focusFirst;
|
||||
@@ -1588,90 +1664,6 @@ body {
|
||||
if (!isNaN(idx) && state.tracks[idx]) playTrack(state.tracks[idx]);
|
||||
});
|
||||
|
||||
/* ---- 音量滑块:点击 + 拖拽(触摸/鼠标) ---- */
|
||||
var volBar = $("vol-bar");
|
||||
if (volBar) {
|
||||
var dragging = false;
|
||||
var lastSent = -1;
|
||||
|
||||
function volFromX(clientX) {
|
||||
var r = volBar.getBoundingClientRect();
|
||||
var pct = (clientX - r.left) / r.width;
|
||||
pct = Math.min(1, Math.max(0, pct));
|
||||
return Math.round(pct * VOL_MAX);
|
||||
}
|
||||
|
||||
function beginDrag(e) {
|
||||
dragging = true;
|
||||
volBar.classList.add("dragging");
|
||||
var v = volFromX(e.clientX);
|
||||
state.volume = v;
|
||||
renderVolume();
|
||||
lastSent = v;
|
||||
}
|
||||
|
||||
function moveDrag(e) {
|
||||
if (!dragging) return;
|
||||
var v = volFromX(e.clientX);
|
||||
if (v === state.volume) return;
|
||||
state.volume = v;
|
||||
renderVolume();
|
||||
// 拖拽中限制发送频率(每 8 个单位发一次),松手时再补一次精确值
|
||||
if (Math.abs(v - lastSent) >= 8) {
|
||||
lastSent = v;
|
||||
setVolume(v, true);
|
||||
}
|
||||
}
|
||||
|
||||
function endDrag(e) {
|
||||
if (!dragging) return;
|
||||
dragging = false;
|
||||
volBar.classList.remove("dragging");
|
||||
try { volBar.focus({ preventScroll: true }); } catch (_) {}
|
||||
collect(); focIdx = foc.indexOf(volBar);
|
||||
var v = e && typeof e.clientX === "number" ? volFromX(e.clientX) : state.volume;
|
||||
setVolume(v); // 最终值一定发送
|
||||
}
|
||||
|
||||
volBar.addEventListener("pointerdown", function (e) {
|
||||
e.preventDefault();
|
||||
// 触摸即视为进入调节态,之后可直接用遥控器左右键微调
|
||||
state.volAdjusting = true;
|
||||
syncVolMode();
|
||||
try { volBar.setPointerCapture(e.pointerId); } catch (_) {}
|
||||
beginDrag(e);
|
||||
});
|
||||
volBar.addEventListener("pointermove", moveDrag);
|
||||
volBar.addEventListener("pointerup", endDrag);
|
||||
volBar.addEventListener("pointercancel", endDrag);
|
||||
|
||||
// 鼠标兼容(Android WebView 84 可能不支持 pointer 事件)
|
||||
volBar.addEventListener("mousedown", function (e) {
|
||||
if (dragging) return;
|
||||
e.preventDefault();
|
||||
state.volAdjusting = true;
|
||||
syncVolMode();
|
||||
beginDrag(e);
|
||||
var up = function (ev) {
|
||||
document.removeEventListener("mousemove", moveDrag);
|
||||
document.removeEventListener("mouseup", up);
|
||||
endDrag(ev);
|
||||
};
|
||||
document.addEventListener("mousemove", moveDrag);
|
||||
document.addEventListener("mouseup", up);
|
||||
});
|
||||
|
||||
// 键盘/遥控器左右键微调音量
|
||||
volBar.addEventListener("keydown", function (e) {
|
||||
var step = e.shiftKey ? 1 : 5;
|
||||
if (e.key === "ArrowLeft" || e.key === "ArrowDown") {
|
||||
e.preventDefault(); setVolume(state.volume - step);
|
||||
} else if (e.key === "ArrowRight" || e.key === "ArrowUp") {
|
||||
e.preventDefault(); setVolume(state.volume + step);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$("btn-refresh").addEventListener("click", function () {
|
||||
var ic = this;
|
||||
ic.classList.remove("spinning");
|
||||
@@ -1700,6 +1692,76 @@ body {
|
||||
});
|
||||
}
|
||||
|
||||
// 音量图标:点击展开面板(遥控器走 __pwRemoteKey 分支)
|
||||
var volBtn = $("btn-vol");
|
||||
if (volBtn) {
|
||||
volBtn.addEventListener("click", function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
FX.press(volBtn);
|
||||
if (state.volPanelOpen) closeVolPanel();
|
||||
else openVolPanel();
|
||||
});
|
||||
}
|
||||
|
||||
// 竖向滑轨:支持触摸/鼠标点按与拖动
|
||||
var volTrk = $("vol-track");
|
||||
if (volTrk) {
|
||||
var vDragging = false;
|
||||
|
||||
function volFromY(clientY) {
|
||||
var r = volTrk.getBoundingClientRect();
|
||||
// 从下往上:底部=0%,顶部=100%
|
||||
var pct = (r.bottom - clientY) / r.height;
|
||||
pct = Math.min(1, Math.max(0, pct));
|
||||
return Math.round(pct * VOL_MAX);
|
||||
}
|
||||
|
||||
function vBegin(e) {
|
||||
vDragging = true;
|
||||
state.volAdjusting = true;
|
||||
syncVolMode();
|
||||
var v = volFromY(e.clientY);
|
||||
state.volume = v;
|
||||
renderVolume();
|
||||
}
|
||||
function vMove(e) {
|
||||
if (!vDragging) return;
|
||||
var v = volFromY(e.clientY);
|
||||
if (v === state.volume) return;
|
||||
state.volume = v;
|
||||
renderVolume();
|
||||
}
|
||||
function vEnd(e) {
|
||||
if (!vDragging) return;
|
||||
vDragging = false;
|
||||
var v = (e && typeof e.clientY === "number") ? volFromY(e.clientY) : state.volume;
|
||||
setVolume(v);
|
||||
}
|
||||
|
||||
volTrk.addEventListener("pointerdown", function (e) {
|
||||
e.preventDefault();
|
||||
try { volTrk.setPointerCapture(e.pointerId); } catch (_) {}
|
||||
vBegin(e);
|
||||
});
|
||||
volTrk.addEventListener("pointermove", vMove);
|
||||
volTrk.addEventListener("pointerup", vEnd);
|
||||
volTrk.addEventListener("pointercancel", vEnd);
|
||||
|
||||
volTrk.addEventListener("mousedown", function (e) {
|
||||
if (vDragging) return;
|
||||
e.preventDefault();
|
||||
vBegin(e);
|
||||
var up = function (ev) {
|
||||
document.removeEventListener("mousemove", vMove);
|
||||
document.removeEventListener("mouseup", up);
|
||||
vEnd(ev);
|
||||
};
|
||||
document.addEventListener("mousemove", vMove);
|
||||
document.addEventListener("mouseup", up);
|
||||
});
|
||||
}
|
||||
|
||||
wire("btn-toggle", togglePlay);
|
||||
wire("btn-prev", playPrev);
|
||||
wire("btn-next", playNext);
|
||||
|
||||
Reference in new issue
Block a user