You can do this by taking advantage of the fact that animate takes a function to call upon completion of the animation. For example:
http://jsbin.com/adokiz/2
What we do is this:
$(document).ready(function() {
var running = false;
$('img').on('click', function(event) {
if (running) return;
running = true;
console.log(this);
$(this).animate({top: '400px'}, function() {
$(this).css({top: 0});
running = false;
});
});
});
With the global variable named running you can prevent multiple clicks from being recognized at the same time. This isn't exactly the same as your code but you can easily adapt it.
Another way to do this which should be even more resistant to being executed twice is using the jQuery one to bind it like so:
$(document).ready(function() {
var animation;
var binding = function() {
$('img').one('click', animation);
};
animation = function(event) {
$(event.target).animate({top: '400px'}, function() {
$(event.target).css({top: 0});
binding();
});
};
binding();
});
Demo: http://jsbin.com/adokiz/3