fix: play/pause button size consistency, add a real volume slider
the play/pause button had no fixed width, so swapping the single-character play glyph for the two-character pause glyph (with the fonts normal spacing between them) visibly widened the button. now a fixed 2.4ch width with tightened tracking on the pause state.\n\nmute only ever toggled — there was no way to set a level. added a small click/drag bar next to it (same interaction as the scrub bar), synced with the video elements own volume/muted state via the volumechange event so it stays correct regardless of how its changed.
This commit is contained in:
+29
-1
@@ -15,6 +15,8 @@
|
||||
var fill = root.querySelector(".player__fill");
|
||||
var time = root.querySelector(".player__time");
|
||||
var mute = root.querySelector(".player__mute");
|
||||
var vol = root.querySelector(".player__vol");
|
||||
var volFill = root.querySelector(".player__volfill");
|
||||
var full = root.querySelector(".player__full");
|
||||
if (!v) return;
|
||||
|
||||
@@ -51,7 +53,33 @@
|
||||
var r = scrub.getBoundingClientRect();
|
||||
if (v.duration) v.currentTime = ((e.clientX - r.left) / r.width) * v.duration;
|
||||
});
|
||||
if (mute) mute.addEventListener("click", function () { v.muted = !v.muted; mute.textContent = v.muted ? "muted" : "vol"; });
|
||||
// volume level, not just mute — click or drag the little bar next to
|
||||
// the mute button, same interaction as the scrub bar
|
||||
function syncVol() {
|
||||
var level = v.muted ? 0 : v.volume;
|
||||
if (volFill) volFill.style.width = (level * 100) + "%";
|
||||
if (mute) mute.textContent = (v.muted || v.volume === 0) ? "muted" : "vol";
|
||||
}
|
||||
function setVolFromEvent(e) {
|
||||
var r = vol.getBoundingClientRect();
|
||||
var level = Math.min(1, Math.max(0, (e.clientX - r.left) / r.width));
|
||||
v.volume = level;
|
||||
v.muted = level <= 0;
|
||||
}
|
||||
if (vol) {
|
||||
vol.addEventListener("click", setVolFromEvent);
|
||||
vol.addEventListener("mousedown", function (e) {
|
||||
setVolFromEvent(e);
|
||||
function onMove(ev) { setVolFromEvent(ev); }
|
||||
function onUp() { document.removeEventListener("mousemove", onMove); document.removeEventListener("mouseup", onUp); }
|
||||
document.addEventListener("mousemove", onMove);
|
||||
document.addEventListener("mouseup", onUp);
|
||||
});
|
||||
}
|
||||
v.addEventListener("volumechange", syncVol);
|
||||
syncVol();
|
||||
|
||||
if (mute) mute.addEventListener("click", function () { v.muted = !v.muted; syncVol(); });
|
||||
if (full) full.addEventListener("click", function () {
|
||||
if (document.fullscreenElement) document.exitFullscreen();
|
||||
else if (root.requestFullscreen) root.requestFullscreen();
|
||||
|
||||
Reference in New Issue
Block a user