0
我有一个可拖动的滑块,并且他可以正常移动,但他不正确停止,在开始和结束时。我该如何停止拖动滑块
function drag (handle, event) {
var diffX = event.clientX - handle.offsetLeft;
document.addEventListener('mousemove', startDrag, false);
document.addEventListener('mouseup', stopDrag, false);
// START
function startDrag (e) {
if (handle.offsetLeft >= 0 && handle.offsetLeft <= 280) {
handle.style.left = (e.clientX - diffX) + "px";
}
e.preventDefault();
}
// STOP
function stopDrag() {
document.removeEventListener('mousemove', startDrag, false);
document.removeEventListener('mouseup', stopDrag, false);
}
}
这是链接到完整的代码 - http://jsbin.com/ojEWalu/4/edit。
我编辑您的jsbin http://jsbin.com/IzexoWI/1/edit – andrew