I'm trying to make a div move with the mouse (game). Here is a piece of jQuery code:
var a = $('.player'); // the div i want it to move
var all = $('.container'); // this is full hight / width container (all the page)
$(all).mousemove(function (e) { // if the mouse move the div move
$(a).animate({
left: e.pageX
},50)
});
it actually work but it have a lag because it detects almost 100 pageX in the second (or that what i think)
so i try to to move it once every 0.5 s to eliminate the lag :
var a = $('.player');
// the div i want it to move
var all = $('.container');
// this is full hight / width container (all the page)
$(all).mousemove(function (e) { // if the mouse move the div move
setInterval(function(){
$(a).animate({
left: e.pageX // move the div once every 0.5 s
},50);
} , 500 );
});
but it doesnt work !