In JQuery ~
I hope to make a simple character moving, Stop > Left || right.
This script make #moveCharacter turn left walk 10px once.
How can I keydown keep turn left walking,when keyup stop walking (like a character)??
// Left moving
$(document).keydown(function(e){
if (e.keyCode == 37) {
$("#moveCharacter").animate({marginLeft: "-=10px"}, {queue:false});
return false;
}
});
2.I try to change keypress() but it has not work…..what wrong?
var xTriggered = 0;
$(document).keypress(function(e){
xTriggered++;
if (e.which == '37') {
$("#moveCharacter").animate({marginLeft: "-="+xTriggered+"px"}, {queue:false});
return false;
}
});
May this code will work as you want
//EDIT