$('#myimage').mousedown(function() {
var img = $(this);
img.stop().animate({
left: ['30px', 'swing'], // calculate new left position
top: ['60px', 'swing'], // calculate new top position
width: ['80px', 'swing'],
height: ['80px', 'swing'],
}, 50, 'swing');
$(document).one("mouseup", function(){
img.stop().animate({
left: ['-5px', 'swing'], // reverse back to original left position
top: ['25px', 'swing'], // reverse back to original top position
width: ['150px', 'swing'],
height: ['150px', 'swing'],
}, 150, 'swing', function() {
$(this).animate({
left: ['20px', 'swing'],
top: ['50px', 'swing'],
width: ['100px', 'swing'],
height: ['100px', 'swing'],
}, 1000, 'swing');
});
});
});
http://jsfiddle.net/diode/G8Ste/598/
EDIT:
To apply the same functionality to all images with the class myimage
, follow these steps:
Store the initial properties of all images by running this code once:
$(".myimage").each(function(i, img){
$(img).data("width", $(img).width());
$(img).data("height", $(img).height());
$(img).data("left", parseInt($(img).css("left"),10));
$(img).data("top", parseInt($(img).css("top"),10));
});
Then in the mousedown
handler:
var img = $(this);
var ww = img.data("width");
var hh = img.data("height");
var left = img.data("left");
var top = img.data("top");
// continue with the rest of the code as shown in the previous example
.