2
我想爲視頻播放器創建一個搜索欄。在滑塊上的mousemove
我想獲取當前值。我希望ValueHover
等於ValueSeeked
。我如何驗證我的測試?獲取懸停輸入類型範圍的值
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/>
你calcSliderPos功能的偉大工程! – bakerhumadi