0
我開發了純javaScript中的音量控制器。鼠標移動工作正常,但不幸的是我無法使它成爲一個完美的音量控制器。 上有功能onmousedown和onmousemove之間的JavaScript衝突
- 捲上的鼠標不改變面臨兩個問題,單擊
onmousemove
功能繼續工作,即使後onmouseup
var vControl = document.getElementById("voumecontrol"); var vNow = document.getElementById("volumenow"); var resultDiv = document.getElementById("result"); vControl.onmousedown = function (e) { vControl.onmousemove = function (e) { var varPosition = e.pageY - vControl.offsetTop; var volPercentage = varPosition/vControl.offsetHeight; kili = Math.abs((e.pageY - (vControl.offsetTop + vControl.offsetHeight))/vControl.offsetHeight); var volumePer = kili * 100; vNow.style.height = volumePer + "%"; resultDiv.innerHTML = "volume position " + volumePer + "%"; } vControl.onmouseup = function (e) { vControl.onmousemove = function (e) { e.preventDefault(); } } }
演示http://codepen.io/anon/pen/kpcvJ