0
我有一个滑动,即时通过使用鼠标移动尝试滑动,但它不会自然移动它跳跃在舞台上,但我不知道为什么。滑动div不平稳移动
我在这里有一个jsfiddle: http://jsfiddle.net/97Mnf/3/您将看到滑块不能正确移动鼠标。
我的代码是:
window.onload = function(){
document.getElementById('cursor').addEventListener("mousedown", mousePos, false);
}
function mousePos(e){
var x = e.pageX;
document.getElementById('cursor').addEventListener("mousemove", function(e){mousemoveCalc(e,x);}, false);
document.getElementById('cursor').removeEventListener("mouseup", mousemoveCalc, false); //not working
document.getElementById('cursor').removeEventListener("mouseout", mousemoveCalc, false); //not working
}
function mousemoveCalc(e,x){
var difx = 0 + parseInt(x + e.pageX);
if(difx > 270){
difx=270;
}else if(difx<0){
difx=0;
}
document.getElementById('cursor').style.left = difx+'px';
}
你从来没有真正设置任何'mouseup'或'mouseout'事件,所以你期望如何去除它们的工作? –
哦,我的坏。解决了第一部分。滑块在小提琴中的移动情况如何? – Sir
您正在通过每次执行'mousePos'来添加多个事件侦听器 –