进度条
进度条组件,通过鼠标拖动来改变进度。progress 直接变化时候会同时触发 change 或 input 事件,因此加一个 mouseDown 的标识,当鼠标不是按下时,只有 progress 变化不触发 change 事件。
<el-slider
v-model="progress"
:show-input-controls="false"
:show-tooltip="false"
@mousedown.native="handleMouseDown"
@change="changeProgress" />
handleMouseDown(value) {
this.mouseDown = true;
window.onmouseup = () => {
this.mouseDown = false; window.onmouseup = null;
};
},
changeProgress(value) {
const seekTime = (value / 100) * this.sound.duration();
this.handleUpdateCurrentTime(seekTime);
},
handleUpdateCurrentTime(seekTime) {
if (this.mouseDown) return; const seek = seekTime || this.sound.seek();
this.progress = (seek / this.duration) * 100;
},