我有这个代码:
jQuery:
var mouseDown=false;
var lastPositionX;
var lastPositionY;
var newX;
var newY;
var lastPositionLeft;
var lastPositionTop;
var newLeft;
var newTop;
$("#insideMap").on("mousedown",function(){
mouseDown=true;
lastPositionX=e.pageX;
lastPositionY=e.pageY;
});
$("#insideMap").on("mouseup",function(u){
mouseDown=false;
});
$("#insideMap").on("mouseleave",function(){
mouseDown=false;
});
$("#insideMap").on("mousemove",function(n){
if (mouseDown){
mouseDown = true; // mantain the boolean to prevent mouseleave trigger
newX=n.pageX-lastPositionX;
newY=n.pageY-lastPositionY;
lastPositionLeft=$("#insideMap").position().left;
lastPositionTop=$("#insideMap").position().top;
newLeft=newX+lastPositionLeft;
newTop=newY+lastPositionTop;
$("#insideMap").css({"left":newLeft,"top":newTop});
lastPositionX=n.pageX;
lastPositionY=n.pageY;
}
});
演示:http: //jsfiddle.net/SkWeX/3/
但是有些东西仍然很糟糕:(它不能很好地工作,它仍然滞后,你能帮我吗?