I have a few divs that follow the mouse position slowly. In the begenning it starts off fine but the closer it gets to the mouse position the slower it gets. I have a very efficient code below but I want to improve it so that the div will always follow the mouse with a constant speed rather than a changing one.
var xp = x, yp = y;
var loop = setInterval(function(){
xp += ((mouseX - xp) ) / 100;
yp += ((mouseY - yp)) / 100;
object.css({left:xp, top:yp});
},20);}
since its diving it by a 100 when it gets closer the math gets smaller causing the X/Y to move slower. I want it to stay the same speed regardless where its coming from.