I want to create a seek bar for a video player. On mousemove
on the slider I want to get the current value.
I expect ValueHover
to equal ValueSeeked
. How can I validate my test?
var valueHover = 0;
function calcSliderPos(e) {
return (e.offsetX / e.target.clientWidth) * parseInt(e.target.getAttribute('max'),10);
}
//attach to slider and fire on mousemove
document.getElementById('seekslider').addEventListener('mousemove', function(e) {
valueHover = calcSliderPos(e).toFixed(2);
document.getElementById('durtimeText').innerHTML = valueHover;
});
document.getElementById('seekslider').addEventListener('change', function(e) {
var valueSeeked = e.target.value;
document.getElementById('seek').innerHTML = valueSeeked;
document.getElementById('test').innerHTML = valueSeeked === valueHover;
});
<input id="seekslider" type="range" min="0" max="100" value="0" step="0.01" style="width:300px;">
<br/>
valueHover : <span id="durtimeText"></span><br/>
valueSeeked : <span id="seek"></span><br/>
valueHover expect to be equal valueSeeked : <span id="test"></span><br/>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…